Search code examples
visual-studiodebuggingvisual-studio-2013envdte

How to select the debugging mode automating Visual Studio?


I have the following code:

Process process = instance.Debugger.LocalProcesses.OfType<Process>().Single(p => p.ProcessID == processId);

process.Attach();

When I run this the debugger attaches using native code and I want to specify managed code. How can I do it?

I haven't found a way to setup the debugging mode.


Solution

  • There is an Attach2 method that allows to specify the engine. It is documented on msdn. You'll need to cast to a Process2 before using it.

    https://msdn.microsoft.com/en-us/library/envdte80.process2.attach2.aspx

    You may also want to wait for the debugger to be running, check out how the Python tools are doing it:

    https://searchcode.com/codesearch/view/28475480/