Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I attach Visual Studio to a process that is not started yet?

I have .NET program that can't be run from Visual Studio for some reasons (Excel file created from an Excel 2010 template project) for which I need to debug startup events.

If I want to debug events that comes after program initialisation there is no problem. I run the program from the explorer, attach the process to Visual Studio and add some breakpoints in the code. But here, I need to put breakpoints on the startup events. I need to be able to attach processes to Visual Studio, not depending on a PID, but on a specific process name or whatever other solution that would work.

Of course adding a Thread.Sleep(1000) in my startup events to give me some time to attach the process in Visual Studio is out of the question!

like image 409
Ucodia Avatar asked Nov 17 '11 13:11

Ucodia


People also ask

Why does Visual Studio say attach instead of run?

You need to create a new Python related project(or open a Python project) in Visual Studio to debug your project which includes the . py file and python codes. Just open a single . py file is not enough to debug the project in Visual Studio, so you will see the “Start” changed to “Attach…”.

What is Visual Studio attach to process?

You can use Attach to Process to debug running apps on local or remote computers, debug multiple processes simultaneously, debug apps that weren't created in Visual Studio, or debug any app you didn't start from Visual Studio with the debugger attached.

How do you attach a process in VS code?

Attach to a running processOpen the folder that contains the source files in Visual Studio Code. Click Run > Start Debugging. Select the configuration you want to use, if prompted. This creates a launch.

How do I ReAttach in Visual Studio?

The hotkey sequence CTRL+R, CTRL+A is used to ReAttach to your latest target (top of the history list). If your process is not currently running, ReAttach will ask you to start it and attach to it as soon as it becomes available.


1 Answers

Actually you can; you don't attach to it, you start it. On the properties of your project, on the Debugging tab, specify the path of the program you want to attach to in the "Command" textbox.

You can also enter any command-line arguments for the program in the "Command Arguments" box:

enter image description here

Ensure that "Attach" is set to "No".

like image 104
Tibi Avatar answered Nov 16 '22 00:11

Tibi