I had a struggle a while back trying to get a pre-build event to fire before my code was compiled.
The pre-build event generates a class that allows me to inspect the revision level of my code and ties the revision to the subversion source code repository.
Today I had a coffee and revisited the problem. I had a lot more success. The magic string is shown below:
"$(ProjectDir)genSvnVer.bat" "" ModuleTracClient
This expands when run on my laptop to:
"C:\Documents and Settings\cgness\My Documents\Visual Studio 2005\Projects\client\ModuleTrac\genSvnVer.bat" "" ModuleTracClient
There are 3 components to the magic command line above.
- The executable needs to be quoted since the $(ProjectDir) macro may expand to something with spaces. C:\Documents and Settings... when parsed by the shell evaluates up to the first space C:\Documents which is not an executable.
- Parameter 1 for the batch file allows me to set the output location concatenated to the current working directory for the output of the script.
- Parameter 2 sets the namespace to be used in the generated C# class.
The script I’m using is the one I posted to the Subversion mailing list but I added a parameter for where to put the output. That will be left as an exercise for the reader.
To debug your pre and post build events simply change to the output window, check if they possibly would work in the command shell and read the errors carefully. Happy shelling!