Daniel Rahamim
Daniel Rahamim

Reputation: 315

Visual studio - Attach debugger to remote process - programatically

I am trying to write code which given a machine and process name, launches the debugger inside the visual studio and connects to the process on the remote machine.

I can do it successfully manually, however, I looked for guides of how to id by using DTE object, and I was unsuccessful.

I tried the following: https://social.msdn.microsoft.com/Forums/vstudio/en-US/69abdaf1-60b1-4ffd-ad33-2d319cb13316/how-do-i-automate-attaching-the-debugger-to-a-remote-process?forum=vsx

And: https://blogs.msdn.microsoft.com/csharpfaq/2011/03/28/how-to-programmatically-launch-debugger-in-a-remote-machine/

At the first solution, nothing happens, and 'LaunchDebugTargets3' method returns non zero code. The second one throws a generic failure exception when calling the method: "AttachDebugger".

Can someone help me this ?

Upvotes: 3

Views: 803

Answers (1)

Daniel Rahamim
Daniel Rahamim

Reputation: 315

Managed to solve it.

        var debugger = dte.Debugger as EnvDTE80.Debugger2;
        var transport = debugger.Transports.Item("Remote");
        var process = debugger.GetProcesses(transport, "remoteMachineName").Item("your-process.exe") as EnvDTE80.Process2;
        process.Attach();

Upvotes: 3

Related Questions