Scenario -
We are building multiple solutions in our Team Build project file. We want to halt the build when the first compile error is encountered.
Answer –
If you are building multiple solutions (sln's) and you encounter error in any sln, the build process will not stop after that sln and will continue to build the rest of solutions. The reason is that MSBuild task in core compile will be invoked for each solution specified in the item group due (@(SolutionToBuild))
To stop the build after getting the build break and not continue building rest of solutions, you need to make the following changes –
ADD -
<!-- If user has not specified the option anything default behavior should be to build all slns --><PropertyGroup>
<StopOnFirstFailure>false</StopOnFirstFailure>
</PropertyGroup>
<!-- In target CORECLEAN -->
<MSBuild
Projects="@(SolutionToBuild)"
StopOnFirstFailure="$(StopOnFirstFailure)"
Properties="Configuration=$(FlavorToBuild); ..."
Targets="Clean" />
<!-- In target CORECOMPILE -->
Condition=" '@(SolutionToBuild)'!='' "
Properties="Configuration=$(FlavorToBuild);..."
Targets="Build" />
<PropertyGroup>
<StopOnFirstFailure>true</StopOnFirstFailure>
If you are building a solution with multiple projects (.xxproj's) and you encounter an error in first .csproj, then build will not stop immediately but will iterate over all the remaining projects (csproj).