Set a pre debug event on Visual Studio 2008

▼魔方 西西 提交于 2019-12-12 11:48:32

问题


I would like to run a task before I start debugging my program in visual studio. I need to run this task every time I debug my program, so a post-build event is not good enough.

I've looked into the "Debugging" tab of the settings, but there is no such option.

Is there any way to do that ?


回答1:


The only thing you can try (IMO) is experiment with the Command property in the Debugging page of your Project Properties ,but i don't think will work.

EDIT: if you want to start a batch file ,do it like this ,

yourbatch.bat $(targetPath)

and in yourbatch.bat you can call you program like this ,

call %1 %2 %3 %4 %5 %6 %7 %8 %9

where %2 ... %3 represent possible programm parameter (supplied by your IDE)

The only thing I am wondering about if your program will debugged directly (I think you may have to attach manually to it in the IDE)




回答2:


Add a pre-build step to the compile options of your "debug" build, and do not have it in the "release" build. (Edit: Pre-build steps are set in the Build Events section of the project properties)

If you are talking about a function or something in the code then use a pre-compiler flag. For example in your Debug build you probably have "_DEBUG" or something similar as a compiler flag... so in the code you can do

#ifdef _DEBUG
doMySpecialTask();
#endif

and it will only get called when using a debug build.

EDIT: Moving info up from comment below: To detect a debugger dynamically at runtime you can use the IsDebuggerPresent() function in Windows. Macs have one as well AmIBeingDebugged(). This is useful if you want your program to behave differently when debugging, but I don't recommend this unless no other options are useful. Modifying the behaviour of the program when debugging might cause the problem to disappear, or manifest in a different manner.



来源:https://stackoverflow.com/questions/5909046/set-a-pre-debug-event-on-visual-studio-2008

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!