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

查看:42
本文介绍了如何将 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天全站免登陆