Installing Entity Framework Core 2.0 in a .NET Framework Class Library Project Yields Invalid References

.net-core-2.0 c# entity-framework-core visual-studio-2017

Question

Using Visual Studio 2017 (15.3.2)

  • Create a .NET Framework class library (4.6.2)
  • Add NuGet Microsoft.EntityFrameworkCore 2.0

You get invalid references to System.Reflection and others.

enter image description here

I can compile, however, in more complicated scenarios when I'm using some functionality of Entity Framework, I am getting run-time exceptions of missing standard System.* libs.

I tried adding the NetStandard.Library first then adding the Entity Framework Core 2 after, but I got the same problem.

I have to use a .NET Framework (Class Lib) as this is a unit test project that is referencing ASP.NETCore2/NETFramework website.

Any clue of what I should be doing?

1
1
10/14/2018 2:34:43 PM

Accepted Answer

This can be fixed by letting MSBuild autogenerate the necessary binding redirects by explicitly setting these two properties inside the csproj file (You can put the <ItemGroup> as a child element below the root <Project> element or add to an exiting <ItemGroup> without a Condition= attribute):

<PropertyGroup>
  <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
  <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>

Note that this may issue warnings if you already have an App.config containing binding redirects. you can remove these redirects.

4
8/29/2017 5:12:38 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow