开发者

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?


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.


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%
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜