I think it is a good idea to move all the lines of events (e.g. post-build events) into a separate batch file.
Therefore, in projectX, instead of having the following in a post-build step for a particular configuration:
echo copy *.exe to d copy "$(OutDir)"*.exe "$(SolutionDir)dist"
appears in the *.vcproj file as (all on one line)
CommandLine="echo copy *.exe to dist&‡x0 D;&‡x0A;copy "$(OutDir)"¦* .exe "¦$(SolutionDir)dist" &‡x0D;&‡x0A;"
(but, replace each ‡ by a #; WordPress seems unable to retain the quoted new-line and/or line-feed entities. It also occasionally forgets backslashes, so I’ve replaced those with a broken pipe: ¦.)
just have this:
call projectX.vcproj.PostBuildEvent.bat "$(OutDir)" "$(SolutionDir)"
with the batch file (named, for example, “projectX.vcproj.PostBuildEvent.bat”) containing something like this:
@echo off REM *** %1 = $(OutDir) *** REM *** %2 = $(SolutionDir) *** echo copy *.exe to dist copy "%~1"*.exe "%~2dist"
[Sometimes you will need to pass the configuration name &c. as an argument, when the steps differ between configurations, i.e. “Release” versus “Debug”]
Why do this?
- With a single batch file it may be easier to keep different configurations in sync;
- It’s easier to compare configurations;
- It’s easier to copy-and-paste to, and compare with, other projects;
- It’s easier to view changes in SVN differences;
- The batch file less likely to result in unresolved conflicts upon an SVN merge or update, and
- easier to resolve when it does;
- The event’s steps may be run separately;
- Any conditional indentation is preserved; I’ve noticed that MSDEV sometimes loses it.
It would probably be best to cater for missing arguments:
... if "%~2" == "" ( echo missing arguments (exiting / defaulting) rem exit 1 call "%~0" "Release" "." ) else ( ... )
Also, perhaps such files should make use of errorlevels…
... copy "%~1"*.exe "%~2dist" || exit 1 ...
It might also we worth setting some variables:
@echo off setlocal set OutDir=%~1 set SolutionDir=%~2 echo copy *.exe to dist copy "%OutDir%"*.exe "%SolutionDir%dist"