如何将Visual Studio附加到尚未启动的进程? [英] How do I attach Visual Studio to a process that is not started yet?

查看:331
本文介绍了如何将Visual Studio附加到尚未启动的进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某些原因(我是从Excel 2010模板项目创建的Excel文件),我需要调试启动事件,因此我的.NET程序无法从Visual Studio运行.

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.

如果我要调试程序初始化后发生的事件,那没有问题.我从资源管理器运行该程序,将该过程附加到Visual Studio,并在代码中添加一些断点.但是在这里,我需要在启动事件上设置断点.我需要能够将流程附加到Visual Studio,而不取决于PID,而是取决于特定的流程名称或任何其他可行的解决方案.

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.

当然,在启动事件中添加Thread.Sleep(1000)可以给我一些时间在Visual Studio中附加该过程!

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!

推荐答案

实际上您可以;您不依附它,而是启动它.在项目的属性的调试"选项卡上,在命令"文本框中指定要附加的程序的路径.

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:

确保将附加"设置为否".

Ensure that "Attach" is set to "No".

这篇关于如何将Visual Studio附加到尚未启动的进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆