How to make MSBuild stop after failing to build one project in a solution


  • I did find lot's of answers to this question, many of which dating back ten years and all of them either out-dated or just not working (patch .targets file of system, add OnError, check MSBuildLastTaskResult, mess around with a temporary .sln.proj file).

    So I'll give it another try:

    1. Given a single solution file Validation.sln, containing the projects AAA.vcxproj and BBB.vcxproj
      where BBB.vcxproj depends on AAA.vcxproj
    2. Running msbuild.exe "Validation.sln"
    3. Project AAA.vcxproj causing a syntax error during compilation.
    4. How can I prevent msbuild from building BBB.vcxproj?

    Please note, that I'm not building multiple solutions - just one.

    Also, the projects are build in parallel, not one-by-one. Changing that is not an option. It's OK if msbuild finishes other independent projects; it just shouldn't start new builds for projects not begun yet.

    Any hints on how I could change project AAA.vcxproj to perform a target/task only if the build failed would be very helpful. The predefined target "AfterBuild" is only executed on success.
    • Edited by Frank Heimes Tuesday, February 27, 2018 5:05 PM Added last paragraph
    Tuesday, February 27, 2018 5:01 PM

All replies

  • Hi Frank,

    Thanks for posting here.

    >>>how I could change project AAA.vcxproj to perform a target/task only if the build failed would be very helpful

    Do you want to execute a specify target when the build failed? If yes, AFAIK, MsBuild will stops execute any further targets when an build error occurs unless ContinueOnError is specify somewhere, like using MSBuild command line:

    msbuild.exe "AAA.sln" /p:ContinueOnError=ErrorAndContinue

    However you can't go edit all installed msbuild files to get that working. The workaround is using OnError element, but this argument has to be set on the target which fails. That mean we have to use this argument on the specify target not all/random targets. So we need to know which target executed failed on project AAA.vcxproject, then add onerror argument to that target. 

    See following thread for some more details:

    Hope this helps.

    MSDN Community Support Please remember to click Mark as Answer. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Wednesday, February 28, 2018 9:23 AM