调试前运行批处理脚本
我想每次在启动程序进行调试之前运行批处理脚本。
对于构建事件,此类功能是使用预构建事件、构建后事件来实现的。
对于实际调试,我找不到任何预调试、调试后事件。
如何实现这个场景呢?
我正在使用 VS2008、.net Framework 3.5、C# 应用程序。
我反对在应用程序中创建一些额外的代码行来启动外部批处理文件。
I want to run a batch script every time before starting program for debugging.
For the build events, such functionality is realized using pre-build event, post-build event.
For actual debugging, I could not find any pre-Debug, post-Debug events.
How to realize this scenario?
I am using VS2008, .net framework 3.5, c# application.
I am opposed to idea of creating some extra lines of code within the application that would fire-up external batch file.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我知道您希望避免额外的代码,但在您的
Main
函数中,您可以使用Debugger.IsAttached()
为您开始工作。例如:
I realise you wished to avoid additional code, but in your
Main
function you could useDebugger.IsAttached()
to kick off your work for you.For example:
您可以使用 VS 宏。
我遇到了同样的问题,这是迄今为止我遇到的最好的问题
对于如何向宏添加事件处理程序有一个很好的解释
此处
到目前为止,我遇到的唯一问题是弄清楚如何获取当前调试的应用程序活动目录
You can use a VS macro.
I had the same issue and this is the best I came with so far
There is a pretty good explanation on how to add event handlers to a macro
here
The only issue I have so far is to figure out how to get the currently debugged application active directory
对我有用的基本解决方案(在 VS 2017 中)是创建一个批处理文件,该文件执行应在调试之前运行的命令,并且还包括作为最后一行的一些通过命令行传递的参数,例如现在,
在调试属性中,将“命令”设置为批处理文件,对于“命令参数”,包括 $(TargetPath) 作为第一个参数,后跟程序使用或需要的任何参数:
YMMV,但对于我的简单需要这似乎运作良好。
A basic solution that worked for me (in VS 2017) was to create a batch file that does the command(s) that should run before debugging, and also include as the last line some parameters to be passed via command-line, such as this:
Now in the debugging properties, set the 'Command' to your batch file, and for 'Command Arguments' include $(TargetPath) as the first argument, followed by any arguments your program uses or needs:
YMMV, but for my simple needs this seems to be working well.
您应该查看... 如何仅针对调试构建运行 Visual Studio 构建后事件
You should check out... How to run Visual Studio post-build events for debug build only
那么,您有一个想要通过预构建事件运行的 .bat 文件吗?
尝试在预构建事件命令中指定批处理文件的完整路径,例如
或
So, you have a .bat file that you want to run via the pre-build event?
Try to specify full path to your batch file in the pre-build event command e.g.
or