28

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).

lmcarreiro
  • 5,312
  • 7
  • 36
  • 63

4 Answers4

17

.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.

Lukasz Szczygielek
  • 2,768
  • 2
  • 20
  • 34
Martin Ullrich
  • 94,744
  • 25
  • 252
  • 217
  • Where do you have this information from? .NET Core 3.0 will only run on .NET Core, not like 2.1 where it is possible to reference the classic framework. https://github.com/aspnet/Announcements/issues/324 – slfan May 16 '19 at 08:23
  • This has nothing to do with ASP.NET Core, the compatibility shims (forwarding assemblies) were an effort in .NET Standard & .NET Core 2.0 - https://github.com/dotnet/standard/tree/master/docs/planning/netstandard-2.0 – Martin Ullrich May 16 '19 at 10:00
  • Can you clarify your caveat more? How can logic in a DLL work, if it can't be loaded or execute at runtime? – Bradley Uffner May 16 '19 at 11:41
  • 3
    some DLLs load and work fine, others won't if they rely on a particular API that is not in .NET Core. That's what the analyzer helps figuring out in advance. – Martin Ullrich May 16 '19 at 12:11
7

It will be the same as today: you will be able to reference .NET Standard libraries. .NET 5 does not contain everything of the classic framework, therefore it won't be possible to reference a .NET 4.x assembly directly. Therefore start to write libraries in .NET Standard.

However in .NET Core 2.0 Microsoft implemented the compatibility shim that allows type forwarding of missing tpyes in old assemblies to the new type. As long as your library does not use any classes that are not supported by .NET 5, you're safe.

See this post or this for more information.

slfan
  • 8,950
  • 115
  • 65
  • 78
1

This is a great question and one that I've spent a fair amount of time trying to answer for myself. One thing that really helped me was to realize that .NET 5.0 is really just the next version of .NET Core.

This video at the 24:30 mark really makes this point well: https://youtu.be/4WJHCvwE2VM?t=1470

With that in mind we can see that things will continue to work as they do in .NET Core 2.0 and earlier where if you want to make use of classic .NET Framework code, then you must first move that code into a .NET Standard class library.

lmcarreiro
  • 5,312
  • 7
  • 36
  • 63
-2

Since.Net don't have all functionalities as .net classic did. You can any DLL from classic to a newer version, infant I've also used libraries from VB in C# and vice versa.

There is one problem though, as long as libraries don't call any unsupported API or APIs that have ended support or have been closed will be a problem.