Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing a .NetStandard 2.0 Nuget package into a VS2015 Net 4.6.1 project

I'm trying to install a Nuget package that targets .NetStandard 2.0 (Microsoft.Extensions.Logging.Abstractions) into a Net 4.6.1 project in Visual Studio 2015. However, while Frameworks should be compatible, it doesn't quite work:

Install-Package : Could not install package 'Microsoft.Extensions.Logging.Abstractions 2.0.0'. You are trying to 
install this package into a project that targets '.NETFramework,Version=v4.6.1', but the package does not contain 
any assembly references or content files that are compatible with that framework. For more information, contact 
the package author.
At line:1 char:1
+ Install-Package Microsoft.Extensions.Logging.Abstractions

I've followed the steps outlined here: Entity Framework Core 2.0 on .NET 4.6.1

So I have installed package "NETStandard.Library.NETFramework", and added

<PropertyGroup>
  <PackageTargetFallback>netstandard2.0</PackageTargetFallback>
</PropertyGroup>

to the csproj. But, no luck there - still the same issue.

Is there any way to install a NetStandard 2.0 package into my project (without upgrading VS or installing any Net Core targeting packs or such)?

Thanks

like image 905
Bogey Avatar asked Oct 17 '17 10:10

Bogey


People also ask

How do I install a NuGet package in a specific project?

From Visual Studio, select Tools > NuGet Package Manager > Package Manager Console. After the Package Manager Console pane opens, verify that the Default project drop-down list shows the project in which you want to install the package. If you have a single project in the solution, it's preselected.

Is .NET standard 2.0 compatible with .NET framework?

NET implementations have support for . NET Standard 2.0, including . NET Framework, . NET Core, and Xamarin.

Is .NET 5 compatible with .NET standard 2?

NET 5 and all future versions will continue to support . NET Standard 2.1 and earlier.


2 Answers

Referencing .NET Standard 2.0 packages is supported using the following:

  • NuGet 3.6.0 or higher for VS 2015 (from NuGet's download site - may not yet be listed as recommended latest)
  • Install the ".NET Standard Support for Visual Studio 2015" from https://aka.ms/netstandard-build-support-netfx (NuGet in VS will also print a link to this in its output window).

There are a still few bugs when consuming .NET Standard 2.0 libraries, especially when mixing .NET Standard < 2.0 and 2.0 libraries but these updates give basic support.

like image 60
Martin Ullrich Avatar answered Oct 17 '22 00:10

Martin Ullrich


Is there any way to install a NetStandard 2.0 package into my project (without upgrading VS or installing any Net Core targeting packs or such)?

I am afraid not. Just like Jon pointed out that the reason for that issue is that you are using Visual Studio 2015.

According to the .NET Standard, .NET Standard 2.0 support .NET Framework 4.6.1 (with .NET Core 2.0 SDK):

enter image description here

So we need install .NET Core 2.0 SDK. And every communication from Microsoft about the preview of .NET Core 2.0 mentions Visual Studio 2017, so I think it's highly recommanded to use Visual Studio 2017 to work with .NET Core 2.0.

Besides, the NuGet package NETStandard.Library.NETFramework is deprecated.

enter image description here

So install a .NetStandard 2.0 Nuget package into a Net 4.6.1 project, I highly recommanded to use Visual Studio 2017 to work with .NET Core 2.0.

Hope this helps.

like image 20
Leo Liu-MSFT Avatar answered Oct 16 '22 23:10

Leo Liu-MSFT