Troubleshooting Custom Build Steps and Build Events
If your custom build steps or events are not behaving as you expect, there are several things you can do to try to understand what is going wrong.
-
Make sure that the files your custom build steps generate match the files you declare as outputs.
-
If your custom build steps generate any files that are inputs or dependencies of other build steps (custom or otherwise), make sure that those files are added to your project.
-
Add @echo on as the first command to see what your custom build step is actually doing. The build events and build steps are placed in a temporary .bat file and run when the project is built, so, you can add error checking to your build event or build step commands.
-
Examine the build log (BuildLog.htm) in the intermediate files directory to see what actually executed.
You can enable the build log by opening the Options dialog box (Tools menu) and then the VC++ Build property page in the Projects folder. Ensure that Build Logging is set to Yes.
-
Verify the values of any file-name or directory macros you are using. You can echo macros individually, or you can add copy %0 command.bat to the beginning of your custom build step, which will copy your custom build step's commands to command.bat with all macros expanded.
-
Run custom build steps and build events individually to check their behavior.
Devenv creates a script like so:
Creating temporary file "blah\BAT00002731085052.bat" with contents
[
@echo off
"blah\IHawkLibTests.exe" -selftest
if errorlevel 1 goto VCReportError
goto VCEnd
:VCReportError
echo Project : error PRJ0019: A tool returned an error code from "Running Unit Tests"
exit 1
:VCEnd
]
Creating command line "blah\BAT00002731085052.bat"
Which is of course wrong.
1 does not indicate an error, anything OTHER than 0 indicates an error. If your exe uses any dlls, and those dlls are not found, then you get an error level < 0 which indicates failure, except that this batch script stupidly ignores that error and reports "Success!"
This needs to be fixed in devenv, but until it is, you need to be careful.
- 9/3/2009
- mark0978