it has been a little while since my last post; hectic bug fixing seems to have been overfilling the brim of my days. i have a few moments of peace before the next onslaught begins, so i thought i would talk about "custom build steps" and "build events" in the c++ project system.

i believe custom build steps were introduced in VC 4. (i could be mistaken, to be honest i never used VC 2 or 4; i briefly evaluated 1.5 for the company i worked for at the time, used VC 5 later, and have worked to some extent or another on 6+). a custom build step is really just a set of command lines that are associated with either a project configuration or a file configuration. the command lines are executed as a batch file, so any valid batch or cmd syntax can be used inside of custom build steps. this is very useful for checking error return values etc.

to set a custom build step, go to the project properties dialog with either the project or a file selected (depending on whether you want a custom build step at the project-level or file-level), select the "custom build step" node in the left-hand pane and enter the commands you want into the "command line" field. you will also need to set the "output" field to the path to a file that the build step generates. (if there is no value for this property the custom build step will never run). the time-stamp of this output file is checked to see if the custom build step needs to be executed; if the file doesn't exist, the custom build step will always execute. you can also enter "additional dependencies" which are other files that will be time-stamp checked to see if the custom build step is out-of-date and needs to execute.

the output of a custom build step is entered into the project's dependency graph, so it is possible, for instance, to set up custom build steps that generate .cpp files and have the build step executed at the correct time (before cl.exe, that is).

the one thing missing in custom build steps is that there isn't any way to set-up a build step that should automatically run on all files of a particular type (like an inference rule in a makefile). we'll be addressing this in whidbey; Peter will likely be covering this in a future entry in his blog.

so that covers custom build steps, what about "build events"? build events were introduced in VC 7. they are sets of command lines, like custom build steps, but instead of running (or not) based on dependency information, they run at a particular time in the build process. VC 7+ support three build events: pre-build (before any other build tool), pre-link (right before the linker) and post-build (after all other build tools). you can't set the output or additional dependencies for a build event, just the command line and whether to run or not ("excluded from build"). a build event, however, will only run if something is out-of-date in the build.

a key to effective use of custom build steps and build events is to use macros wherever possible. rather than hard-coding paths, use macros that point to the appropriate locations. this not only makes it easier to share projects among a team, but helps make the projects more maintainable. also remember that the command lines for these tools is executed as a batch file. anything you can do in a batch file or cmd script you can do in a custom build step or build event, and this gives you quite a bit of power.