Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I add a reference to a .NET Framework DLL from a .NET 5 project?

Tags:

Microsoft recently announced at Build 2019 that the next major version of .NET will unify both .NET Core 3.* and .NET Framework 4.* into a single .NET platform, which the major version number will be 5.

I didn't understand it well, does it mean that using .NET 5 I will be able to add references to libraries written in both version of .NET?

For example, a .NET 5 project referencing 2 assemblies, one that was compiled targeting .NET Core 3 and another compiled targeting .NET Framework 4.5 (in this case, as it references a .NET Framework library, I think it would only be able to run on Windows).

like image 282
lmcarreiro Avatar asked May 07 '19 17:05

lmcarreiro


People also ask

Can I use .NET framework DLL in .NET 6?

Yes, you can load . NET Framework assemblies into . NET Core 5 and 6.

Can you reference .NET framework from .NET core?

The answer is no, we cannot use . NET Framework Base Class Library in . NET Core because of compatibility issues. Basically, the libraries which target .

Is .NET 5 compatible with .NET standard 2?

NET 5 and all future versions will always support . NET Standard 2.1 and earlier. The only reason to retarget from . NET Standard to .

How do I migrate .NET framework to .NET 5?

Migrating from . NET Core or . NET 5. In Visual Studio, simply right click on your project in Solution Explorer and choose Properties. Under Application > General > Target framework, choose .


1 Answers

.NET 5 will have the same compatilbity layer that .NET Core currently has.

This allows you to reference .NET Framework DLLs with the caveat that the DLL may not load or execute at runtime. If it is a logic library, it may work well. Not so much if it relies on e.g. System.Web. This is especially useful for 3rd party libraries which you don't have the source code for. You can use the The .NET Portability Analyzer to check for any use of unsupported APIs in such libraries.

That being said, you should try to change your existing .NET Framework libraries to .NET Standard or multi-target to both .NET Framework and .NET Standard.

like image 81
Martin Ullrich Avatar answered Sep 19 '22 12:09

Martin Ullrich