Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TreatSpecificWarningsAsErrors support for NuGet warnings #8797

Closed
davkean opened this issue Nov 7, 2019 · 5 comments
Closed

TreatSpecificWarningsAsErrors support for NuGet warnings #8797

davkean opened this issue Nov 7, 2019 · 5 comments
Labels
Area:ErrorHandling warnings and errors/log messages & related error codes. Resolution:Duplicate This issue appears to be a Duplicate of another issue Type:Feature
Milestone

Comments

@davkean
Copy link

davkean commented Nov 7, 2019

Original: dotnet/project-system#5562.

(Opened on behalf of https://github.com/arialdomartini)

Visual Studio Version:

VS2019, Rider 2019.2.2, Command Line

$ dotnet --info
.NET Core SDK (reflecting any global.json):
 Version:   3.0.100
 Commit:    04339c3a26

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.17134
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\3.0.100\

Host (useful for support):
  Version: 3.0.0
  Commit:  7d57652f33

.NET Core SDKs installed:
  2.0.3 [C:\Program Files\dotnet\sdk]
  2.1.2 [C:\Program Files\dotnet\sdk]
  2.1.4 [C:\Program Files\dotnet\sdk]
  2.1.100 [C:\Program Files\dotnet\sdk]
  2.1.201 [C:\Program Files\dotnet\sdk]
  2.1.202 [C:\Program Files\dotnet\sdk]
  2.1.302 [C:\Program Files\dotnet\sdk]
  2.1.500 [C:\Program Files\dotnet\sdk]
  2.1.502 [C:\Program Files\dotnet\sdk]
  2.1.509 [C:\Program Files\dotnet\sdk]
  2.1.801 [C:\Program Files\dotnet\sdk]
  2.1.802 [C:\Program Files\dotnet\sdk]
  2.2.103 [C:\Program Files\dotnet\sdk]
  2.2.104 [C:\Program Files\dotnet\sdk]
  2.2.402 [C:\Program Files\dotnet\sdk]
  3.0.100 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download

Summary:

csproj's directives like

<NoWarn>
    NU1702
</NoWarn>

and

<WarningsAsErrors>
    NU1702;1702
</WarningsAsErrors>

are ignored by dotnet build.

Steps to Reproduce:

  1. Create a solution.
  2. Create a netcoreapp2.0 or a netcoreapp3.0 project A
  3. Create a class library targeting net472 called B
  4. Edit A's csproj and add to it:
<PropertyGroup>
    <TreatWarningsAsErrors>True</TreatWarningsAsErrors>
    <WarningsAsErrors>NU1702</WarningsAsErrors>
</PropertyGroup>
  1. Reference B from A
  2. Compile the solution with dotnet build

Expected Behavior:
A compilation error.

Actual Behavior:
The compilation succeeds, with a warning NU1702, which is not treated as an error.

Additional notes:

The reference from NetCoreApp to .NET 4.7.2 project raises a NU1702 warning, which should be treated as an error, given the directive:

<PropertyGroup>
    <WarningsAsErrors>NU1702</WarningsAsErrors>
</PropertyGroup>

I also tried with

<PropertyGroup>
        <TreatSpecificWarningsAsErrors>NU1702;1702</TreatSpecificWarningsAsErrors>
</PropertyGroup>

and

<PropertyGroup>
        <TreatSpecificWarningsAsErrors>NU1702;1702</TreatSpecificWarningsAsErrors>
</PropertyGroup>

and even by placing those directives in the PropertyGroup node where <TargetFramework> is.

Possible related issues:

I noticed different behaviors depending on:

  • B being referenced as a project in the same solution
  • B being referenced as a NuGet package
  • B being using the classic csproj file format vs the new SDK csproj format
@davkean
Copy link
Author

davkean commented Nov 7, 2019

@arialdomartini I don't believe NuGet supports <TreatSpecificWarningsAsErrors/> for its warnings, so this bug would be tracking that request.

@rizi
Copy link

rizi commented Apr 28, 2020

It's also not possible to suppress the NU1702 warning with:
<NoWarn> NU1702 </NoWarn>

is there any solution that NU1702 does not generates a warning?
br

@nkolev92
Copy link
Member

nkolev92 commented May 7, 2020

Dup of #6288.

Instead of TreatSpecificWarningsAsErrors, you can use WarningsAsErrors

@nkolev92 nkolev92 closed this as completed May 7, 2020
@nkolev92 nkolev92 added Resolution:Duplicate This issue appears to be a Duplicate of another issue and removed Type:DCR Design Change Request Partner:Project-System labels May 7, 2020
@AdrianSanguineti
Copy link

It's also not possible to suppress the NU1702 warning with:
<NoWarn> NU1702 </NoWarn>

is there any solution that NU1702 does not generates a warning?
br

@rizi, if you haven't already seen it, there is a workaround listed in #8093 where you can add <MSBuildWarningsAsMessages>NU1702</MSBuildWarningsAsMessages> to suppress NU1702 until the NuGet client is updated to support reading of NoWarn (see the issue details).

@rizi
Copy link

rizi commented Jul 21, 2020

It's also not possible to suppress the NU1702 warning with:
<NoWarn> NU1702 </NoWarn>
is there any solution that NU1702 does not generates a warning?
br

@rizi, if you haven't already seen it, there is a workaround listed in #8093 where you can add <MSBuildWarningsAsMessages>NU1702</MSBuildWarningsAsMessages> to suppress NU1702 until the NuGet client is updated to support reading of NoWarn (see the issue details).

Thx, I must have missed that.
Br

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area:ErrorHandling warnings and errors/log messages & related error codes. Resolution:Duplicate This issue appears to be a Duplicate of another issue Type:Feature
Projects
None yet
Development

No branches or pull requests

6 participants