Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

For a .Net Core 2.1 project, Why does Nuget restores .Net 4.6.1 packages?

Tags:

c#

.net-core

If a package is not available for .Net Core how do we enforce strict .Net runtime version checking during, Install-Package command?

Install-package command, why does Visual Studio even, restores .Net 4.6.1 version, just to give a runtime error at later stages!

I'm sure VS team has thought about it and there must be a reason! As well as a mechanism to validate & strict runtime version checking during Install-Package.

Warnings:

Warning NU1701 Package 'Microsoft.AspNet.Identity.Core 2.2.2' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project.

Edit: I just took one of the full .net framework packages, as example.

Intention was to ask how to prevent it from happening in Nuget package manager.

Warning NU1701 Package <any full .net framework package> was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project.

like image 720
Abhijeet Avatar asked Nov 07 '18 12:11

Abhijeet


People also ask

Where does NuGet restore put packages?

For projects using PackageReference, after a successful restore, the package should be present in the global-packages folder and the obj/project. assets. json file is recreated. For projects using packages.

Does .NET core use NuGet?

NET (including . NET Core), the Microsoft-supported mechanism for sharing code is NuGet, which defines how packages for .

Where are .NET core NuGet packages stored?

The location of the default global packages folder. The default is %userprofile%\. nuget\packages (Windows) or ~/. nuget/packages (Mac/Linux).

What does dotnet restore do?

The dotnet restore command uses NuGet to restore dependencies as well as project-specific tools that are specified in the project file. In most cases, you don't need to explicitly use the dotnet restore command, since a NuGet restore is run implicitly if necessary when you run the following commands: dotnet new.


1 Answers

It's explained by Microsoft in this GitHub issue. Quoting the relevant part:

[...]

Whenever you use NuGet packages that go through the compat shim you'll get a warning like this:

Warning NU1701: Package 'Huitian.PowerCollections 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.

We've made sure you get this warning every time you build (rather only during package restore) to ensure you don't accidentally overlook it.

The idea here is that we have no way of knowing whether the .NET Framework binary will actually work. For example, it might depend on WinForms. To make sure you don't waste your time troubleshooting something that cannot work, we let you know that you're potentially going off the rails. Of course, warnings you have to overlook are annoying. Thus, we recommend that you test your application/library and if you're convinced everything is working fine, you suppress the warning:

[...]

So if the package works, then you can suppress the warning. If it doesn't, you'll have to use a different package or wait for the package to support your target framework.

like image 160
user247702 Avatar answered Sep 22 '22 15:09

user247702