5
votes

I am running into an issue when I try to reference a .net 4.7 DLL in my Asp.NetCore 2 MVC app. The error is pasted below:

PM> Install-Package Microsoft.NETCore.App -Version 2.0.0 Restoring packages for ../Web.csproj... Install-Package : Package Microsoft.NETCore.App 2.0.0 is not compatible with net47 (.NETFramework,Version=v4.7). Package Microsoft.NETCore.App 2.0.0

supports:

  • netcoreapp (.NETCoreApp,Version=v0.0)
  • netcoreapp2.0 (.NETCoreApp,Version=v2.0)

The .Net 4.7 assembly is an entity framework 6 library which will be used by the web app(core2 mvc). I have updated my core 2 web app to target multiple frameworks (netcoreapp2.0;net4.7).

So I guess what im trying to ask is how I can use a .Net4.7 assembly in an ASP.Net core2.0 solution.

1
What you really want is a netstandard version of the library; what library is it? does a netstandard version exist?Marc Gravell♦
it also looks like you're actually doing the opposite thing here, and trying to install netcore 2.0 into a net 4.7 project; can you be very clear what you're trying to do here? I'm confused by that install-package line. What is Web.csproj here, and what does it target?Marc Gravell♦
A .Net Framework 4.7 library can be utilized (via .NET Standard) in a .NET Core 2.0 project, but not the other way around, i.e. a library that targets .NET Core 2.0 cannot be installed in a project that targets .NET Framework 4.7.Chris Pratt
@MarcGravell - I am trying to using a .Net 4.7 Framework assembly (Entityframework 6 project) in a core 2 web project.To achieve that I added <TargetFrameworks>net47</TargetFrameworks> on the web project file.CodeNoob
@ChrisPratt, to confirm a netcore 2.1 project (WebApi) can target a netstandard 2.0 project (Logic) which in turns consumes a .net framework 4.7.1 library (WCF Class Lib).IbrarMumtaz

1 Answers

3
votes

K, piecing things together:

  • you had a .NET Core Web project
  • you wanted to add Entity Framework 6 (EF 6), but it wouldn't add
  • so you added <TargetFrameworks>net47</TargetFrameworks> to the csproj

Adding <TargetFrameworks>net47</TargetFrameworks> is a huge change - it means it is not actually a .NET Core project any more. The csproj often requires quite a bit of cleanup from such a foundational change, but it may be possible to make it work again, but ultimately: you no longer have a .NET Core project if you do that.

You may be better off removing that net47 reference, and migrating from EF 6 to EF Core (Microsoft.EntityFramework.Core) - which targets .NET Standard 2.0. This will have some API differences from EF6, but is almost certainly the more appropriate approach.

If you want a .NET Framework web project, I'd probably recommend starting from the .NET Framework template.