开发者

Set a pre debug event on Visual Studio 2008

开发者 https://www.devze.com 2023-03-03 22:04 出处:网络
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 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 "De开发者_高级运维bugging" tab of the settings, but there is no such option.

Is there any way to do that ?


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)


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消