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 applicat
There isn't a good solution to this problem. The call idea does cause other scripts to run. I have noticed that error detection will not work. Put 'exit /b 1' into FailMe.cmd The use 'call FailMe.cmd' in the post build steps. Notice the build does not fail? I am using VS 2017 building a C# project. Now try it with 'FailMe.cmd' The build now reports an error.
So you might be better off just using a single script, if error reporting is important.
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.
Adding to womp's answer:
If you have multiple property sheets with something to do on the same build event you can do the following to chain the commands:
%(Command)
echo foo
where %(Command)
expands to the previous value of the command.
Personally I do this for all build events, even if I currently do not have inherited commands, because this ensures there will be no problems if I add property sheets later on.
The approach suggested by womp works in Visual Studio 2015/2017 (Windows), but doesn't work in Visual Studio for Mac (Preview), which seems to execute only the first of the commands. The only approach that I found working in both Mac and Windows versions of Visual Studio was chaining 2 MSBuild commands:
<Target Name="AfterResolveReferences">
<Exec Command="path\MyFirstCommand.exe -parameters" />
</Target>
<Target Name="MySecondCommand" AfterTargets="AfterResolveReferences" >
<Exec Command="path\MySecondCommand.exe -parameters" />
</Target>
The above example uses "AfterResolveReferences" event but should obviously work for PostBuild event too.
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.