Search code examples
visual-studio-2012msbuilddevenv

Visual Studio 2012 Command Line Building - Detecting Build Failures


I'm setting up a build server for a Visual Studio 2012 project and I'm trying to add detection for failed builds so the server can properly recover after a build failure and notify users of the failure and the error message.

I'm using devenv.exe with the "/Build" and "/Out" switches, however for building, the "/Out" switch captures all build output and stores in the specified file, and I only want it to capture build errors.

Does anyone have any suggestions on how I can only have build errors written to the file, or better ways of detecting a build failure?

Thank you in advance!


Solution

  • If you just need a pass/fail, you could use ERRORLEVEL in a batch/cmd script. It's primitive, but would probably work for most cases. Something like this:

    @devenv Solution.sln /Build
    @if ERRORLEVEL 1 echo Build Failed
    

    You could also use MSBuild, which has options for console output (i.e. /clp:ErrorsOnly) as well as file output. Something like this:

    msbuild /p:Configuration=Debug /t:Rebuild /clp:ErrorsOnly Solution.sln