11

I'm working on a .NET Core CLI app that needs to reference a 3rd party NuGet package that has not been published with a netcoreappX.X target. I've run the Analyze Project Portability tool on it and got 100% compatibility, which is expected, as this is a relatively simple library.

The problem then comes in the form of this annoying NuGet warning:

Warning: NU1701
Package 'XXXXXX 1.0.0' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETCoreApp,Version=v2.0'. This package may not be fully compatible with your project.

Is there a way to hide this warning for a specific NuGet package?

Sergio Leon
  • 485
  • 6
  • 12

3 Answers3

19

I found an answer to my question in a Google Images search, which led me to this seemingly unrelated SO post:

Suppressing issues from Roslyn code Analyzers

In short, the Properties page of the NuGet package reference has a NoWarn attribute where the error code can be specified, as shown in the following image:

enter image description here

Edward Brey
  • 40,302
  • 20
  • 199
  • 253
Sergio Leon
  • 485
  • 6
  • 12
  • thanks for sharing your solution here, you could mark it as the answer, so it could help other community members who get the same issues. – Leo Liu Aug 21 '17 at 02:47
  • Also work with VS 2022. [Official documentation](https://learn.microsoft.com/en-us/visualstudio/ide/how-to-suppress-compiler-warnings?view=vs-2022) – NicolasF Feb 07 '22 at 21:22
1

As of VS2019 (v 16.9.1) you can add the code (or codes, comma separated) to the property Suppress Warnings, then rebuild the solution.

NuGet Package Properties

Matthew M.
  • 932
  • 10
  • 17
  • 2
    Using the Suppress Warning on a root NuGet package works, but a dependency package can also cause a warning that is not suppressed. Example in a .NET 6 class library using NuGet package: iTextSharp, which depends on BouncyCastle. The warning for iTextSharp goes away, but the BouncyCastle warning stays. Thoughts? – Brett Jul 23 '22 at 19:18
1

Edit your project (.proj) file and suppress the warning codes at the project level.

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    <NoWarn>NU1701;RAZORSDK1006</NoWarn>
  </PropertyGroup>
James Lawruk
  • 30,112
  • 19
  • 130
  • 137