Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
908 views
in Technique[技术] by (71.8m points)

debugging - 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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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".


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...