Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Project not compatible with netcoreapp2.0

I'm trying to add a full framework class library as a project reference to asp.net core 2.0 MVC project and getting the below error.

Project XYZ is not compatible with netcoreapp2.0 (.NETCoreApp,Version=v2.0). 
Project XYZ supports: net462 (.NETFramework,Version=v4.6.2) 

I have updated to the most recent version of Visual studio i.e, 15.3.5. Is it even possible to reference 4.6.2 libraries in core 2.0 projects?

like image 860
Ranjith Balmoori Avatar asked Sep 26 '17 15:09

Ranjith Balmoori


2 Answers

The first thing that you can try is to compile the library you want to consume as netstandard2.0. Theoretically (according to the .net standard documentation), this will make it compatible with projects using net461 and later as well as netcoreapp2.0 and later.
In practice, sometimes you will end up with a problem with one of your dependencies that don't provide the same library version across different compilation targets.

In such cases you may simply need to add the .net core 2.0 as a target framework for the XYZ library.
The xml tag listing the targets is <TargetFrameworks> in the XYZ.csproj file and is not handled by the Gui of the project's properties.
So I would give a try at editing the XYZ.csproj by hand and add or replace what's listed as <TargetFrameworks> with netcoreapp2.0.
If you are adding it as additional target you need to separate them with ';' as in

<TargetFrameworks>net462;netstandard2.0;netcoreapp2.0</TargetFrameworks>

More details about this in this Microsoft doc.
Please keep in mind that this will trigger multiple compilations and will slow your build consequently...

like image 142
chaami Avatar answered Sep 28 '22 22:09

chaami


It should be. Microsoft announced a ".NET Framework Compatibility Mode" with the release of .NET Standard 2.0. However, they didn't go into great detail about how it works exactly, or what to troubleshoot if it doesn't. Additionally, they only specific talk about it in relationship to Nuget packages, so it's possible there's some role Nuget is playing in the process, as well. Unfortunately, I've been unable to find any additional information about this feature outside of the announcement post.

That said, Microsoft's explicit recommendation is to not rely on the fact that your .NET Framework library may just happen to work in .NET Core; instead, you should be actively porting .NET Framework libraries you control to .NET Standard. I'd say you're likely going to spend more time trying to figure out why it doesn't "just work" than you would porting your code, so that it will definitely work, and be future-proof to boot.

like image 27
Chris Pratt Avatar answered Sep 28 '22 23:09

Chris Pratt