简体   繁体   English

Visual Studio - 以编程方式将调试器附加到远程进程

[英]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.我正在尝试编写给出机器和进程名称的代码,在 Visual Studio 中启动调试器并连接到远程机器上的进程。

I can do it successfully manually, however, I looked for guides of how to id by using DTE object, and I was unsuccessful.我可以手动成功完成,但是,我寻找了如何使用 DTE 对象进行 id 的指南,但没有成功。

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我尝试了以下操作: 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/和: 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.在第一个解决方案中,没有任何反应,并且“LaunchDebugTargets3”方法返回非零代码。 The second one throws a generic failure exception when calling the method: "AttachDebugger".第二个在调用方法时抛出一个通用的失败异常:“AttachDebugger”。

Can someone help me this ?有人可以帮我吗?

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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM