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.
One little solution that might suit many people.
in the first line of code that the exe will run, add this command
System.Threading.Thread.Sleep(20000)
That will make the exe sleep for 20 seconds before it starts processing anything. Then you have 20 seconds to attach to the process, which can be done quickly with ctrl+alt+p, then find the process, then enter to attach.
Not much of an answer but worked a treat for me :--)
I found this answer when I was looking for something similar. In my case, I couldn't simply use the executable as my project's startup program because it needed to be started in a very specific environment that I couldn't reproduce easily (namly: started from cygwin).
I took a look at the Reattach Extension as suggested by mrstrange and also the very similar Attach To Anything extension... but my executable seemed to close too quickly for the extensions to notify and attach.
What finally helped me was this: https://stackoverflow.com/a/4042545/1560865, which references the MSDN article How to: Launch the Debugger Automatically, which in-turn lists the following steps:
debugger
. vsjitdebugger.exe
. Hope that this helps anyone else in the future!