How to stop a build after error in compilation using MSBuild

Mohammad Mohsin Siddiqui 175 Reputation points
2023-03-21T11:01:39.09+00:00

I have vcxproject with only one target. I have 20 logical core machines. Totals cpp source files for target is 44 files. There is one header (base header) which all sources files includes.

Now if there is any error in one of the source file, MSBuild does not stop there rather its builds all 44 sources files and in terns, all source files failed to compile. I don't see any reason to spawn a new set of cl after finding an error from the first set.

So if I build that target like below

msbuild -v:m -m /p:CL_MPcount=20 sample.vcxproj

This will launch 20 instances of cl for compiling 20 different files. The behavior I am looking is if any f the sources files failed while compiling this first , msbuild does not launch new cl.exe. But it always compiles all 44 files.

I found StopOnFirstFailure and ContinueOnError property for msbuild targets. Which I set like below but nothing did work.

msbuild -v:m -m /p:CL_MPcount=20 /p:StopOnFirstFailure=true sample.vcxproj

OR

msbuild -v:m -m /p:CL_MPcount=20 /p:StopOnFirstFailure=true /p:ContinueOnError=false sample.vcxproj

OR

msbuild -v:m -m /p:CL_MPcount=20 /p:ContinueOnError =false sample.vcxproj

Please help me to find out how I can achieve this.

The real problem happens when errors comes from some template function and that template functions is being consumed by multiple sources files, VS generates so much warnings/errors messages in output pane that it almost every time hangs Visual Studio

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,599 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,526 questions
{count} vote

1 answer

Sort by: Most helpful
  1. Dou Xu-MSFT 165 Reputation points Microsoft Vendor
    2023-03-22T03:24:14.4+00:00

    Hello @Mohammad Mohsin Siddiqui,

    Thanks for taking time to post this issue in Microsoft Q&A forum.

    The doc MSBuild Task - MSBuild | Microsoft Learn says StopOnFirstFailure: 
    If true, when one of the projects fails to build, no more projects will be built.
    Currently this is not supported when building in parallel (with multiple processors).

    Here’re suggestions you can try:

    1 set /p:CL_MPCount=1

    2 set /p:BuildInParallel=false

    3 search in the VS Marketplace to see if there is a suitable extension

    https://marketplace.visualstudio.com/

    Feel free to contact us.

    Sincerely,

    Douxu

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments