Friday, July 15, 2005

VS 2003 Post-Build Events

I'm sure this is old hat to folks experienced in Visual Studio, but it's something new for me. Maybe someone else will find this useful. Post-Build Events in Visual Studio let you handle things like moving or copying files around your build environment. Very handy stuff if you need to do a little massaging of your solution/project's output. I'm working on a CodeSmith template project which has a Helper class to do string manipulation, type parsing, etc. (I wasn't the guy who did the initial work, that was another fellow more smarter than I am.) The DLL generated from the Helpers class needs to land in the template directories for use by CodeSmith. Create Post-Build events on a per-project basis by right-clicking on the project and pulling up the Properties dialog. Click on Build Events under the Common Properties folder. The Post-Build Event Command Line field is where you can enter your commands at. You can enter in any command-line executable in this field. Use the field's elipsis to pull up another dialog where you can enter longer commands. The "Macros" button on this dialog also gives you access to a handy set of properties for the build -- you'll find a list of directories, paths, etc. Construct your commands, one per line, using free text and macros as needed. Use any regular command like 'copy', 'move', etc. You can also call other batch files via the 'call' command. Important: Remember to surround paths with quotes in case your paths have spaces in them. The Post-Build Event actually creates a batch file in the project's output directory, then calls it after the build is complete. All macros you use are expanded when that file's written, so it's a good source of information when trying to troubleshoot a failed post-build event. You can quickly see if you forgot to do something like surrounding your path with quotes. Not that I know anyone who'd make such a basic mistake. I'm just tossing that out there for others.


Anonymous said...

I prefer doing the same with external tools, because that assembly cannot be overwritten when CodeSmith Studio is loaded.

Anonymous said...

Thanks a lot for the article. i did the mistake of not including the quotes.

Luc said...


I found you on a google search for 'vs 2008 pre-build event command line'. :) Nice trick with the bat file mention. It'll help me debug my problem. Great article, and... small world. :)

Subscribe (RSS)

The Leadership Journey