Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop MSBuild processing immediately on compilation errors

I have written a batch file, which when executed builds a visual studio solution. The solution comprises of few C# projects. I am using MSBuild utility for this. How can i stop the build from proceeding further when there are compilation errors in any of the projects? Further how can i get the error messages and display them on command prompt?

like image 772
Ananya Avatar asked Mar 15 '11 12:03

Ananya


2 Answers

There's no support for stop on first failure when building a visual studio solution.

You can workaround this by taking the following steps:

  1. Set the environment variable msbuildemitsolution to 1 (set msbuildemitsolution=1);
  2. Invoke MSBuild in order to generate a *.proj file from the target VS solution;
  3. In the generated *.sln.proj file change RunEachTargetSeparately="true" in the target named Build to RunEachTargetSeparately="false";
  4. Invoke MSBuild to build the updated *.sln.proj file.

This answer is based on Dan Moseley answer to a post on MSDN Forums.

like image 179
João Angelo Avatar answered Oct 12 '22 09:10

João Angelo


It would be easier to give you an answer if you would have posted relevant parts of your batch file. Nevertheless, for your second part of the question, here is an example how I solved almost the same issue in one of our build scripts:

msbuild.exe /m /p:Configuration=Release /v:n theSolutionFile.sln >Build.log
if ERRORLEVEL 1 goto :showerror
find "0 Warn" Build.log >nul:
if ERRORLEVEL 1 goto :showerror

goto :EOF

:showerror
echo Build error occurred
exit %ERRORLEVEL%
like image 4
Doc Brown Avatar answered Oct 12 '22 10:10

Doc Brown