21

Microsoft just announced that Entity Framework Core 2.0 will now run on .NET Standard 2.0.

.Net Standard 2.0 is compatible (if that's the right term here) with .NET Framework 4.6.1.

However when I try add the latest NuGet package I get an error telling me that I'm using the wrong version:

 Install-Package : Could not install package 
 'Microsoft.EntityFrameworkCore.SqlServer 2.0.0-preview2-25332'. 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. 

If according to the announcement I can use EF Core 2.0 with .NET Framework 4.6.1, can someone please explain, and if possible give an example of what that would look like.

user281921
  • 661
  • 2
  • 8
  • 25

4 Answers4

7

It seems that in order to include .NET Standard 2.0 libraries within a .NET 4.6.1 project you need to include the NetStandard.Library.NetFramework NuGet package.

Example of current version in the packages.config file:

<package id="NETStandard.Library.NETFramework" version="2.0.0-preview1-25305-02" targetFramework="net461" />
user281921
  • 661
  • 2
  • 8
  • 25
  • 1
    VS 2017 15.5 preview 3 or later does this for you "automagically" – ErikEJ Jul 04 '17 at 06:28
  • 2
    This package has been deprecated in favour of using Nuget 3.6+ – Alex Wiese Sep 06 '17 at 08:19
  • @AlexWiese is correct. I would also like to note there is a pitfall using nuget 3.6 under VS2015, it seems to have a [bug](https://github.com/NuGet/Home/issues/6403). However, I used 2017 to install the project. – petrosmm Mar 29 '19 at 14:10
3

In addition to installing the NETStandard.Library.NETFramework package, you may also have to tell older NuGet clients that it really is compatible by adding the following to your *.csproj file.

<PropertyGroup>
  <PackageTargetFallback>netstandard2.0</PackageTargetFallback>
</PropertyGroup>
bricelam
  • 28,825
  • 9
  • 92
  • 117
1

go to your .csproj and change your TargetFramework

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

to it

  <PropertyGroup>
    <TargetFramework>netcoreapp2.0</TargetFramework>
  </PropertyGroup>
Italo José
  • 1,558
  • 1
  • 17
  • 50
0

Run Update-Package via Package Manager Console, this will somehow magically update all packets including .Net Core which by default would prevent you from updating them via Nuget, because it needs NetCore 2.0 target, while you're targeting 4.6.1 even though it should be compatible.

Project will work perfectly if you do this and hopefully soon updates will be viable directly via nuget as they meant to be.

Aistis Taraskevicius
  • 781
  • 2
  • 10
  • 31