Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix build check build submission errors (#10227)
Fixes #10071 Context While building with buildcheck enabled and MSBUILDNOINPROCNODE=1 Severity of the rule set to Error, does not reported to the all build: image This is since buildcheck error is not added into the _warningsAsErrorsByProject, WarningsAsErrors == null && _warningsAsErrorsByProject == null is true all the time. so HasBuildSubmissionLoggedErrors always return false. msbuild/src/Build/BackEnd/Components/Logging/LoggingService.cs Lines 577 to 587 in 843bfa5 public bool HasBuildSubmissionLoggedErrors(int submissionId) { // Warnings as errors are not tracked if the user did not specify to do so if (WarningsAsErrors == null && _warningsAsErrorsByProject == null) { return false; } // Determine if any of the event sinks have logged an error with this submission ID return _buildSubmissionIdsThatHaveLoggedErrors?.Contains(submissionId) == true; } Treat warning as errors or message, the buildcheckResultWarning doesn't initialize the code. So when the code of BuildWarningEventArgs is null. ShouldTreatWarningAsError returns false all the time. msbuild/src/Build/BackEnd/Components/Logging/LoggingService.cs Lines 1897 to 1908 in a9c95c7 /// <returns><code>true</code> if the warning should be treated as an error, otherwise <code>false</code>.</returns> private bool ShouldTreatWarningAsError(BuildWarningEventArgs warningEvent) { // This only applies if the user specified /warnaserror from the command-line or added an empty set through the object model if (WarningsAsErrors != null) { // Global warnings as errors apply to all projects. If the list is empty or contains the code, the warning should be treated as an error if ((WarningsAsErrors.Count == 0 && WarningAsErrorNotOverriden(warningEvent)) || WarningsAsErrors.Contains(warningEvent.Code)) { return true; } } Changes Made when buildEventArgs is BuildErrorEventArgs, treat BuildErrorEventArgs' related warnings as errors Initialize the code of BuildCheckResultWarning that is inherited from BuildWarningEventArgs Testing Manually testing on local now set MSBUILDNOINPROCNODE=1 and change the build_check.BC0101.Severity= Error dotnet D:\WORK\msbuild\artifacts\bin\bootstrap\net8.0\MSBuild\MSBuild.dll FooBar.csproj /m:1 -nr:False -restore -analyze Change build_check.BC0101.Severity= warning dotnet D:\WORK\msbuild\artifacts\bin\bootstrap\net8.0\MSBuild\MSBuild.dll FooBar.csproj /m:1 -nr:False -restore -analyze -warnaserror
- Loading branch information