Skip to content

WarningsNotAsErrors ignored for some warnings with /warnaserror option #10874

@rainersigwald

Description

@rainersigwald

Given

<Project>
  <PropertyGroup>
    <MSBuildTreatWarningsAsErrors>true</MSBuildTreatWarningsAsErrors>
    <MSBuildWarningsNotAsErrors>ABC123</MSBuildWarningsNotAsErrors>
  </PropertyGroup>

  <Target Name="Dispatch">
    <ItemGroup>
        <P Include="$(MSBuildThisFileFullPath)" AdditionalProperties="Num=1" />
        <P Include="$(MSBuildThisFileFullPath)" AdditionalProperties="Num=2" />
        <P Include="$(MSBuildThisFileFullPath)" AdditionalProperties="Num=3" />
        <P Include="$(MSBuildThisFileFullPath)" AdditionalProperties="Num=4" />
    </ItemGroup>
    <MSBuild Projects="@(P)" BuildInParallel="true" Targets="Warn" />

  </Target>

  <Target Name="Warn">
    <Warning Code="ABC123" Text="Hello from instance $(Num) in pid $([System.Diagnostics.Process]::GetCurrentProcess().Id)" />
    <Exec Command="sleep 1" /><!-- To give worker nodes some time to spin up -->
  </Target>
</Project>

The MSBuildWarningsNotAsErrors is not consistently respected:

dotnet msbuild -m .\foo.csproj /warnaserror

  foo succeeded with 1 warning(s) (0.0s)

    C:\Users\raines\Downloads\foo.csproj(19,5): warning ABC123: Hello from instance 1 in pid 39896

  foo succeeded (0.0s)

    C:\Users\raines\Downloads\foo.csproj(19,5): error ABC123: Hello from instance 4 in pid 3804

  foo succeeded (0.0s)

    C:\Users\raines\Downloads\foo.csproj(19,5): error ABC123: Hello from instance 3 in pid 5872

  foo succeeded (0.0s)

    C:\Users\raines\Downloads\foo.csproj(19,5): error ABC123: Hello from instance 2 in pid 8016


Build failed with 3 error(s) and 1 warning(s) in 0.2s

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: DebuggabilityIssues impacting the diagnosability of builds, including logging and clearer error messages.Area: EngineIssues impacting the core execution of targets and tasks.Priority:1Work that is critical for the release, but we could probably ship withouttriaged

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions