Saeid
Saeid

Reputation: 13592

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

Upvotes: 17

Views: 12752

Answers (2)

Yahya Hussein
Yahya Hussein

Reputation: 9121

I do not know what made Microsoft allow referencing .net framework class library into .net core project but as a programmer, I am happy with this allowance.

You see allowing .net core application to reference .net framework libraries is useful in case you want to start with windows and are planning to go cross platform in the future.

We are in a stage where many useful open source libraries do not fully support .net core till the date of this post, masstransit is an example, so when I am developing a new software I will be using .net core project that depends on such libraries and I will update them later when they support .net core.

Upvotes: 4

Daniel A. White
Daniel A. White

Reputation: 191037

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.

Upvotes: 9

Related Questions