Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET Core project add reference to .NET Framework project. Why it's possible?

I have followings projects:

.NET Core 2.0 Web Application

.NET Standard 2.0 Class library &

.NET Framework 4.5 Class Library.

I add reference of .net framework class library to asp.net core web api project. and it seems it works very well.

I am wondering why it's possible to add reference of .NET Framework class library project to ASP.NET Core Web API or MVC?

It's not supposed to allow adding only Standard or Core libraries references to Core projects? Is this core Web project with .NET Framework class libraries references still cross platform?

UPDATE

According to Phiter comment:

"If you import a .net framework library to your project it'll no longer be cross platform, but you can do it freely if you want to. They allow it because you might want to use .net core and still be on windows."

So if this is a reason, if I want to bind my project to .NET Framework and remain on windows why I use Core Web Project from the first place?

I thought we use core projects for cross platform ability and if not, the .Net framework is not a better option?

UPDATE

mason comment:

"Nothing funny: ASP.NET Core project doesn't have to run on .NET Core. It can also be run on .NET Framework.

Just because it's called 'Core' doesn't mean they're related. They could have called it ASP.NET FancyPants and had it run on .NET Core and .NET Framework and you wouldn't be as confused. Microsoft just sucks at naming things."

UPDATE (November 12, 2018)

A first look at changes coming in ASP.NET Core 3.0 - Fully leveraging .NET Core

As announced on the .NET Blog earlier this month, .NET Framework will get fewer of the newer platform and language features that come to .NET Core moving forward, due to the in-place update nature of .NET Framework and the desire to limit changes there that might break existing applications. To ensure ASP.NET Core can fully leverage the improvements coming to .NET Core moving forward, ASP.NET Core will only run on .NET Core starting from 3.0. Moving forward, you can simply think of ASP.NET Core as being part of .NET Core.

Customers utilizing ASP.NET Core on .NET Framework today can continue to do so in a fully supported fashion using the 2.1 LTS release. Support and servicing for 2.1 will continue until at least August 21, 2021 (3 years after its declaration as an LTS release) in accordance with the .NET Core support policy.

like image 447
Saeid Avatar asked Dec 18 '17 18:12

Saeid


People also ask

Can .NET Core Reference .NET framework projects?

NET Core 3.1) projects to reference . NET Framework libraries on Windows-only. Referencing . NET Framework libraries doesn't work for all projects, such as if the library uses Windows Presentation Foundation (WPF) APIs, but it does unblock many porting scenarios.

Can you mix .NET Core and .NET framework?

At this point, if your NuGet dependencies are compatible with both your netcore and netframework targets you may be done! The big news here is that most of your NuGet dependencies are compatible with both. All of the most downloaded NuGet packages are either multi-targeted, or have packages for each target.

How do I add a reference to a dotnet core project?

One method of adding references to your library is by typing it directly in the project. json file. As you can see that we have added some references under the dependencies section as shown in the following code. Let us now save this file and you will see that references are added to your library now.

Can I reference .NET Framework .NET 6?

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


1 Answers

This was just added as part of .NET Standard/Core 2.0. As long as the .NET Framework dll only references things in the .NET Standard, it will use type forwarding to the .NET Core implementations.

like image 145
Daniel A. White Avatar answered Nov 22 '22 03:11

Daniel A. White