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!
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:
Ensure that "Attach" is set to "No".