5

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.

6
  • 2
    What you really want is a netstandard version of the library; what library is it? does a netstandard version exist? Commented Feb 6, 2018 at 13:00
  • 3
    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? Commented Feb 6, 2018 at 13:01
  • 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. Commented Feb 6, 2018 at 16:10
  • @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. Commented Feb 7, 2018 at 5:42
  • @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). Commented Sep 6, 2018 at 13:50

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I have decided to use EF Core. Thank you so much for your advice. .Net core is a new playing ground for me.
EF now targets .net core 3 too (through .net standard 2.1)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.