Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide .NET Core compatibility warnings when referencing .NET 4.6 NuGet package in VS 2017.3

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?

like image 323
Sergio Leon Avatar asked Aug 17 '17 15:08

Sergio Leon


People also ask

How do you suppress nu1603?

From the right-click or context menu, select Properties. In the NoWarn box of the package's properties, enter the warning number you want to suppress for this package. If you want to suppress more than one warning, use a comma to separate the warning numbers.

Can I use net framework NuGet in .NET core?

Net Framework will not be part of the . Net Standard, particularly once you get into those areas that have been most heavily refactored by . Net Core (e.g. ASP.Net). You can use this extension for visual studio to check the compatibility.

What is PrivateAssets?

PrivateAssets is a metadata tag used to control dependency assets. You might be using a dependency purely as a development harness and might not want to expose that to projects that will consume your package. In this scenario, you can use the PrivateAssets metadata to control this behavior.


2 Answers

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

like image 192
Sergio Leon Avatar answered Sep 19 '22 18:09

Sergio Leon


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

like image 24
Matthew M. Avatar answered Sep 17 '22 18:09

Matthew M.