Sunday, August 15, 2010

Ignore Error From Visual Studio Post Build Event

If, for whatever reason, you want to execute a command from a Visual Studio build event, and you don't care if that command returns an error, then do the following:
[command to execute] 2>nul 1>nul
The 2>nul 1>nul will swallow the stderr and stdout from the command. The EXIT 0 will make sure the build event returns 0.

This post explains how MSBuild decides whether or not a command executed in a build event has failed. If you control the command your executing, you may be able to change how it writes to stderr and stdout and avoid swallowing those streams. If you don't control the command, you'll have to swallow.

This technique may not be helpful if your build event is more complicated. But if your situation matches this simple scenario, the technique works like a champ!


  1. Rob,

    Interesting. I had a similar experience with a post build event affecting my project build. In my case it was the result of formatting my stdout messages.

    See my post here -->

    - Chris

  2. I could not get the above to work, I ended up using the info provided on StackOverflow:

  3. Was just having this exact problem, and your solution did the trick. Thanks!