StopOnFirstFailure flag is respected when we are building multiple solutions and find the error in 1st solution and stop building the rest of solutions. However when we have a scenario where a solution contains multiple projects (csproj’s) and 1st project has error, the build continues to build the remaining projects and this flag does not have any effect.
StopOnFirstFailure flag says -
… for each of the “things” I passed into the Projects parameter of the <MSBuild> task, please build them all even if one of them fails (StopOnFirstFailure=false), or please stop as soon as any of them fails (StopOnFirstFailure=true). In team build case, the “thing” you’re passing in is a .SLN. So <MSBuild> task will attempt to build the whole .SLN, regardless of your StopOnFirstFailure setting. The behavior of .SLN builds is defined as attempting to build all projects within it, even if one of them fails, and there’s no easy way to change that behavior.
If you still want to immediately stop the build on getting the build break, then you need to know the list of projects that are contained within the SLN. You need to pass list of projects to the Projects parameter of <MSBuild> task. Since team build does not have this information at disposal, there is no easy way to fix it.