Visual Studio: Multiple post-build commands?

There is another option: you can separate the commands with &&. E.g.

copy $(TargetPath) d:\folder1 && copy $(TargetPath) d:\folder2

This is not exactly the same as separating with newlines: with &&, if the previous command failed, next commant will not run.

Separating by newlines is easier to read, so you should prefer it. However I know at least one case when && is useful. It is the scenario, when you use property sheets to have different post-build steps on different machines. VS 2008 doesn't allow setting PostBuildStep in property sheets directly, but you can add a user macro with your command and call it from the main project settings. A macro is single line, so you can use && to have multiple commands there.


You can type in as many post build commands as you want. Just separate them by newlines.

Here's an example from one of my projects.

Post Build Event Commandline


Important: When executing a batch file, you must use the "call" statement on order the following lines to be executed. If you don´t use "call", the execution goes into the .bat and doesn´t return to the following lines. Same as on DOS prompt.

e.g.:

call MyBatch1.bat
call MyBatch2.bat

Each command should be on a separate line. What I found though is that if there's an error executing one of those commands the whole post-build fails and so you'll need to try each post-build command one at a time to debug.