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

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.

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.

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.

Related

Referencing .net(4.7.1) projects in .net core 2.2

I have a .net Core 2.2 project. This is created using a Webapplication (Model View Controller) template. I can add my .Net Framework 4.7.1 projects into this core project, it compiles, run - and is deployed on my test servers.
1) Then I read about 2.2 End of Life, and I tried to migrate this to 3.1, and I cannot reference .Net Framework 4.7.1 in 3.1 framework. I don't know what is my next step here.
2)I read that I can convert my dll's to .Net Standard and reference - but, how can I do this?
3)These 4.7.1 dll's are shared by .Net Framework projects and core projects, so if I change this to .Net Standard - will my .Net Framework applications work?
4) Also - should I migrate my 2.2 Core projects to 3.0 because of the EOL? Is that mandatory? How will EOL affect audits if I don't migrate?
First, 2.2 is EOL, because 2.1 is the LTS release. You can downgrade to 2.1 if you don't want to jump to 3.x yet, and you'll still have a year or two of support there, I think.
However, 3.x takes the first step towards the new vision of one .NET (.NET 5 for all workflows), so the sooner you can get there, the better. 3.1, specifically, is the LTS release for 3.x, so stick there if you don't want to be forced to upgrade again for a while.
.NET Core 3.x implements .NET Standard 2.1, which is why you can no longer target .NET Framework with that (no version of .NET Framework implements .NET Standard 2.1 and never will). However, .NET Standard 2.0 is supported by both .NET Core (2.x and 3.x) and .NET Framework 4.6.1+. As a result, if you need to share a library between all these targets, you should target .NET Standard 2.0.
As far as converting your existing libraries go, you simply change the target framework to .NET Standard 2.0. That's literally it. Once you do that, some functionality in the library may fail (anything that requires .NET Framework, i.e. Windows-specific APIs). At that point, you either need to rewrite those parts of the library to use .NET Standard-compatible APIs, or use compiler directives to sub-in alternate implementations for .NET Standard 2.0/.NET Core, at which point, you'd have to multi-target the library (i.e. .NET Framework and .NET Standard 2.0 or even specifically .NET Core). When compiling, DLLs will be generated for each specific target, allowing you to seamless reference the same library from projects targeting any of the library targets.
If you're doing anything with ASP.NET Core components in your libraries, you should factor that code out into separate libraries and target .NET Core 3.1 directly there. There's no point in targeting .NET Standard 2.1, as that code will only ever be applicable to .NET Core, anyways. You should also work in the opposite direction. In other words, if there's anything that's only applicable to .NET Framework projects (Web Forms, etc.), then factor that out into separate libraries that will only target .NET Framework. That will allow you to migrate the remaining parts of the library more easily to .NET Standard 2.0.

How to add EF CLass Library to solution that will work with .net 4.5 and dotnet core

I currently have a webforms website using .net 4.5.
I would like to add a class library with entity framewrok.
I want to make sure that this class library works with dotnet core and my existing webforms project.
With all the versions of .net, it is very confusing.
From what I gathered, dotnet standard maybe used as the middle ware for this type a situation. But I'm not sure this is true.
Any suggestions?
Yes, you'll have to use the .NET Standard and Entity Framework Core. .NET Framework will be able to interface with the .NET Standard
I would start up with https://www.youtube.com/watch?v=ECNLyvxLnuQ
There's not a lot of docs on standard, but this will give you some conceptual understanding
Notice that "ASP.NET vs ASP.NET Core" and "Entity Framework vs Entity Framework Core" are completely different frameworks, even though which were named similarly.
ASP.NET and Entity Framework targets .NET Framework which means they can only work on .NET Framework.
ASP.NET Core and Entity Framework Core targets .NET Standard which means they can work on both .NET Framework and .NET Core.
WebForms bases on ASP.NET, and there is no (and not planned) migration for it on ASP.NET Core, so the old WebForms projects will never be able to work on .NET Core.
It is a great quantity of the task migrating from ASP.NET MVC to ASP.NET Core MVC, and WebForms is even impossible.
If you really need to run your project on .NET Core, there will be a complete refactoring of your whole project:
Refactoring your WebForms project to ASP.NET Core MVC (Completely redevelop the whole project)
Refactoring your Entity Framework data definitions to Entity Framework Core (It only supports code-first and database-first, there is no model-first any more)
Make sure that all referenced .NET libraries target .NET Standard or .NET Core and reference them on nuget. If not, re-target an alternative.
If your project is planned to be hosted on Linux server and referenced some native libraries, you have to get the equivalent .so libraries instead of .dll libraries.

.Net Core Assembly issues

I am converting an existing .Net framework 4.6.2 Project into a .Net core project. I have some of the DLLs in the .Net framework 4.6.2, while some DLLs are not supported in .Net core. Below is the list of those DLLs. Can any one give me the solution?
System.ComponentModel.Composition
System.Runtime.Remoting
system.serviceModel
The following is based on a comment I added to the question:
System.Web and System.ComponentModel.Composition are both supported and provided for .NET Core version 2.0, as can be seen here and here.
(as a side note: https://apisof.net/ is a wonderful resource, provided by Microsoft to aid in figuring out which APIs are available in the different .NET platforms).
But System.Runtime.Remoting is not supported by .NET Core at this time.
The listing for System.ServiceModel shows that it is supported in .NET Core, but only when Platform Extensions is included along side it.
If you need access to Windows or .NET Framework specific APIs, then it's recommended that you don't use .NET Core for the project or create a .NET Standard class library/project which includes the .NET Framework specific code and consume the outputs of that.
The following are some resources to help with .NET Core and .NET Framework API specific issues:
https://apisof.net/
Immo Landwerth's videos on what .NET Standard is, and how it relates to the different .NET Platforms (he's the PM for .NET Standard)
A blog post I wrote about .NET Standard and how it fits into the .NET ecosystem
A blog post from codeshare.co.uk describing the key differences between .NET Framework and .NET Core
A blog post from Stackify discussing the differences in .NET Framework and Core API space

What's the difference between ASP.NET 5, .NET Core, and ASP.NET Core 5? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
The community reviewed whether to reopen this question 1 year ago and left it closed:
Original close reason(s) were not resolved
Improve this question
I'm confused on the distinction between these terms:
ASP.NET 5 (now renamed ASP.NET Core and released as 1.0, not 5.0)
ASP.NET Core 5
.NET Core
Can anyone briefly explain it?
ASP.NET 5 (now ASP.NET Core 1.0)
Is the next generation of ASP.NET that provides a familiar and modern framework for web and cloud scenarios. It includes the next versions of ASP.NET MVC, Web API, Web Pages and SignalR. It is a high-performance and modular design, and supports full side by side to make it seamless to migrate from on premise to the cloud. These products are actively developed by the ASP.NET team in collaboration with a community of open source developers. Together we are dedicated to creating the best possible platform for web development.
Update: It has been renamed from ASP.NET 5 to ASP.Net Core 1.0.
.NET Core:
.NET Core is the small optimized runtime that is the basis of ASP.NET Core. It currently runs on Windows, Linux, and Mac. It is a high-performance and modular design, and supports having several applications on a web server each one with its own copy of the .NET Core runtime, enabling a full side by side experience, and that will make it easy to adopt new .NET Core versions without affecting other apps, and this makes .NET Core architecture a leap forward from the current classic .NET 4.6. These products are actively developed by the .NET team and in collaboration with a community of open source developers. Together we are dedicated to improving and extending the .NET platform with new features and for new scenarios.
.NET Core has two major components. It includes a small runtime that is built from the same codebase as the .NET Framework CLR. The .NET Core runtime includes the same GC and JIT (RyuJIT), but doesn’t include features like Application Domains or Code Access Security. The runtime is delivered on NuGet, via the Microsoft.CoreCLR package.
.NET Core also includes the base class libraries. These libraries are largely the same code as the .NET Framework class libraries, but have been factored (removal of dependencies) to enable us to ship a smaller set of libraries. These libraries are shipped as System.* NuGet packages on NuGet.org.
For more information, see Introducing .NET Core
ASP.NET 5 is a new platform based on DNX (.NET Execution Environment). DNX is on duty for loading CLR. There're two kind of DNX now: for Full .NET CLR (from .NET Framework) and for CoreCLR. CoreCLR is a new cross-platform light CLR (runs on Win/Linux/Mac).
ASP.NET 5 works seamlessly on CLR/CoreCLR as DNX abstracts it from runtime being used.
IL assemblies build for old .NET still be used with new CoreCLR and DNX. So ASP.NET 5 functionality is a bunch of nuget packages.
Strictly speaking there're no such things as "asp.net core 5" and ".net core" now (as CLR != .NET). There's "ASP.NET 5 running on CoreCLR".
IMO it's better to consider "ASP.NET 5" as ".NET 5".
There is no ASP.net Core 5 yet. In fact, Microsoft decided to change the .net 5 (The version after 4.6) to a brand new name : .net Core
So the version released on June 2016 is actually .net Core 1.0
The reason why they gave it a new name is the very fundamental change they've made in it.
These fundamental changes include :
Cross platform: It works on Windows/Linux/Mac as opposed to the previous versions working only on Windows/IIS
It's fully open source now and you can see every bit of its code in GitHub.
Its performance (especially in ASP.net) is way better than the previous versions, as you can easily customize your request pipeline according to what you need (through middlewares).If you are familiar with nodejs and ExpressJs framework it's so similar to ExpressJs. In some cases it performs better than NodeJs. Have a look into this benchmark.
It's designed with a modern mindset of app development, for highly distributed cloud applications, microservices and containers (docker)
ASP.NET Core is the next version of ASP.NET MVC 5, Yes, the version number is confusing! It has gone through a few name changes. It started as ASP.NET vNext, then changed to ASP.NET 5, next was renamed to ASP.NET MVC 6 and eventually became ASP.NET Core 1.0.
The main difference between ASP.NET and ASP.NET Core are
Platform Independent Features, ASP.NET Core provides hosting in multiple platform (Win / Linux / Mac OS) hosting (Cross platform).
Introduced new lighter version of CLR and assemblies with non-dependent frameworks.
Frameworks are a complete rewrite (removal of dependencies with DI) and Its Open source Project.
Project default project template is updated with Type scripts insted of JQuery.
Improved new security features and completely decoupling for all its dependent framework.
Updated project template with angular and json based configuration & enhanced packages support with node modules.
Supports for Visual Studio IDE ( 2015 v3 + 2017 and above) & VS Code IDE.
If you are new to this, Please refer Here
By the way there is also a Mono runtime as an alternative to CoreCLR in the linux apt and Docker package. Mono is still the default when it's up to installing DNX. The whole thing about the "Core" is that it's a cross platform .net framework and at some point hosting an ASP.NET 5 app will not make use of IIS, Apache, Mono etc., but the DNX and Libuv.
.NET Core 1.0 is not the next version of .NET 4.6.2 (Full .NET Framework). If it is the next version it should have more features than the previous version. But according to Microsoft .NET Core 1.0 doesn't have some of the features .NET 4.6 got. That's why they named it as .NET Core 1.0 instead of .NET 5.
In ASP.NET Core 1.0 they are using .NET Core 1.0 as reference. That means we don't need to install .NET framework to run our ASP.NET Core 1.0 application.
You can find more updated information here.
ASP.NET Core i.e 1.0/2.0...
ASP.NET Core is an open-source, cross-platform framework for building modern, cloud-based web apps on Windows, macOS, or Linux.
ASP.NET i.e ...4.5/4.6
ASP.NET is a mature framework that provides all the services needed to build enterprise-grade, server-based web apps on Windows.
There is no such thing as ASP.NET Core 5 and .NET Core.
ASP.NET 5 is same as ASP.NET Core 1.0
Please refer to the link:
https://learn.microsoft.com/en-us/aspnet/core/choose-aspnet-framework?view=aspnetcore-2.0

Class library that can be shared between .NET Framework and .NET Core

I have a big class library written in .NET 4.0 but when I reference it in a Store App that uses .NET Core, it shows an error. And further, Microsoft just released .NET Core for the next version of .NET.
I want to know what type of project will be able to be shared by both .NET 4.6 and .NET Core? Is a class library able to do that?
It seems that the release of .NET Core specialized for Store Apps causes confusion for me.
If you have a PCL (Portable Class Library) that works for Metro apps, it will definitely run on the fully fledged .NET (aka, your normal ASP.NET, WF, WPF applications).
That means that you don't have to do anything, besides porting your existing library to be compatible with the PCL you choose.
There is a new target called dotnet which you can use to target the platforms DNX, UWP and .Net 4.6. Effectively, this libraries are build against .Net Core packaged libraries instead of the libraries of the full .Net Framework.
Read more here: https://oren.codes/2015/07/29/targeting-net-core/ and related posts.

Resources