Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET Core 2.1 can't reference a .NET Framework 4.7.2 Class library

Tags:

.net

.net-core

I have a .NET Core 2.1 app, a .NET MVC website (4.7.2) and I also have a .NET 4.7.2 class library.

What I'm trying to do is have my core 2.1 project reference the class library.

Now I've added the reference to the core project with no issues (it builds), but when I try to add the namespace to a class It doesn't come up.

I want both the app and the MVC site to share the same class library.

Here's the screen shot:

There should be another namespace, one called models

There should be another namespace, one called models

Any help would be great. Thanks

like image 523
Scott L Avatar asked Sep 19 '18 13:09

Scott L


People also ask

Can we use NET Framework class library in .NET Core?

If you want to use full . NET Framework libraries, you can only target . NET Framework, unless you use multi-targeting and provide alternate implementations of those libraries for the . Net Core targets.

How do I add a reference to .NET Core library?

Add Class Library Reference To use a class library in your application, you must add a reference to the library to access its functionality. Right click on the project name of your console app in Solution Explorer and select Add ->Reference option.


1 Answers

You can reference .NET Standard library instead. So you need to create .NET Standard library with common shared logic and reference it from both - .NET Core and .NET Framework ("full") projects.

Note that while you may be able to use .NET Standard without PackageReference, it's recommended to do it this way. Find more details in Referencing .NET Standard Assemblies from both .NET Core and .NET Framework.

like image 87
Dmitry Pavlov Avatar answered Sep 16 '22 15:09

Dmitry Pavlov