Take the 2-minute tour ×

Visual Studio 2008 lets me declare a command and attach it to the post-build event for a project. Like a lot of developers, I use it regularly to xcopy files to the application output directory.

I am working on a project where I need to xcopy files from two different places to two different destinations, all within a single project. In other words, I need to invoke two different xcopy commands from the same post-build event. It looks like the post-build event will only take a single command, and that if I need to invoke multiple commands, I will have to put the commands in a *.bat file and call that from the post-build event.

Is that correct, or is there a simpler way to invoke two commands from the post-build event? Thanks in advance for your help.

share|improve this question
add comment

5 Answers

up vote 57 down vote accepted

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:

alt text

share|improve this answer
Including a screen-shot is only useful if you intend to host it forever. –  OWenJ23 Oct 22 '12 at 20:11
@OWenJ23 ...or 'imageshack' in this case ;) –  Anthony Walsh Apr 1 '13 at 10:29
add comment

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.


call MyBatch1.bat
call MyBatch2.bat
share|improve this answer
+1 Thanks. This saved me some grief I was experiencing. –  Bernard Apr 4 '12 at 20:53
Thanks!!! This was exactly what I was looking for! –  Alex Loop Jul 6 '12 at 12:44
+1 from me, too. Completely forgot about that detail and was pulling my hair out. –  Greg Apr 18 '13 at 16:25
add comment

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

Just prefix "call " to your batch script. So that statements below the Batch script is also executed after returning the call from batch script.

call Script1.cmd
call Script2.bat
share|improve this answer
add comment

Your Answer


