Search code examples
entity-frameworknugetvisual-studio-2017.net-framework-version

Entity Framework 6.1.3 NuGet Install Fails for target framework .NETStandard 1.4


Within Visual Studio 2017, I add a class library project to solution with framework '.NET Framework 4.5.2'. Inspection of newly created project properties shows the 'Target Framework' as '.NETStandard 1.4'. The 'Target Framework' dropdown, only lists frameworks starting '.NETStandard...'.

On attempting to install Entity Framework 6.1.3 via NuGet for the new class library, I receive the following error:

Package EntityFramework 6.1.3 is not compatible with netstandard1.4 (.NETStandard,Version=v1.4). Package EntityFramework 6.1.3 supports:
  - net40 (.NETFramework,Version=v4.0)
  - net45 (.NETFramework,Version=v4.5)
One or more packages are incompatible with .NETStandard,Version=v1.4.
Package restore failed. Rolling back package changes for 'Mercury.Test3'.

Given I can't reset target framework to '.NET Framework 4.5.2' how do I overcome NuGet's reluctance to install EF 6.1.3 against '.NETStandard 1.4'.

Thanks in advance.


Solution

  • The simplest answer is that since your class library is declaring that it works on all platforms that support .NETStandard 1.4, it cannot take a dependency on a component that has narrower requirements (e.g. EF 6.1.3, which only works with .NET Framework 4.x).

    This is in a way similar to what happens when you need to add a reference that specifically targets x86 or x64 on a project that targets Any CPU: you are forced to change the project to use the same PlatformTarget.