What is the difference between creating a project ASP.NET Core (.NET Core) and ASP.NET Core (.NET Framework) - c#

I don't see clearly the main difference between the last two project types, actually which sense have the last one? .NET Core and .NET Framework?

The difference is whether you will be targeting the .Net Core Framework or the Full .Net Framework. And this difference shows up for example in the project.json file.
Another thing to know about is that when you use the "ASP.NET Core Web Application (.NET Framework)" template it's much easier to link to .Net Library Projects that target the full framework when using Visual Studio. It's possible to do it using the "ASP.NET Core Web Application (.NET Core)" template but it requires some manual editing of the project.json file.
It may also be worth mentioning that if you target the Full Framework the web application must be deployed on Windows, whereas targeting the .Net Core framework allows the web application to be deployed to non-Windows environments. But the .Net Core Framework is not as feature rich as the Full Framework. (It has no drawing routines for resizing images for instance). You can read more about choosing the right framework here: https://docs.asp.net/en/1.0.0-rc1/getting-started/choosing-the-right-dotnet.html
Either way, no matter which of these two templates you select, you will be creating a project for creating an ASP.NET Core application.
Some differences in the actual projects created
Here is what the solution looks like in Visual Studio 2015 Update 3 when "ASP.NET Core Web Application (.NET Core)" is chosen (with Empty option):
And here is its project.json file:
Here is what the solution looks like in Visual Studio 2015 Update 3 when "ASP.NET Core Web Application (.NET Framework)" is chosen (with Empty option):
And here is its project.json file:

ASP.NET Core can run on top of .NET Core or the full .NET Framework. So there's a template depending on whether you want to build on .NET Core or the full .NET Framework.
Here's an infographic that Microsoft put together that visually demonstrates the concept:
No matter which template you choose, you can always edit your configuration to target both at the same time. But the templates just help you get started with one or the other.

Related

Why does a dotnet Core App with a reference to a classic .Net project works and compiles [duplicate]

I'd really like to start using .NET Core and slowly migrate applications and libraries to it. However, I can't realistically upgrade my entire code base to use .NET Core and then go through the process of testing and deploying a plethora of applications in production.
As an example, if I create a new .NET Core application and try to reference one of my .NET Framework projects I get the following:
The following projects are not supported as references: -
Foobar.NetFramework has target frameworks that are incompatible with
targets in current project Foobar.NetCore.
Foobar.NetCore: .NETCoreApp,Version=v1.0
Foobar.NetFramework: .NETFramework,Version=v4.5
Is it possible to create a new .NET Core application and reference my existing .NET Framework libraries? If so, what's the process for doing that? I've spent hours going through Microsoft's documentation and searching their issues on GitHub, but I can't find anything official on how to achieve this or what their long-term vision is for this process.
Old question, but with the release of .NetStandard 2.0 and .netcore 2.0 and vs2017.3, the game has changed.
You can use the Full .NET Framework (TFM) with .NetCore 2.0, but how?
In Visual Studio 2017.3, you can reference the Full .NET Framework (any version) directly from within a .NetCore2 project.
You can build the .NetStandard2 class library and reference your TFM. Then reference your .NetStandard2 library from your .NetCore2 project.
For example, referencing json.net net45 from .NetStandard2.
Browse to the folder and select version net45 (not netstandard1.3)
See the dependency in the image below, no yellow warning as you see.
Even if a Nuget library is not ready to be ported to .Netstandard 2, you can use any API in the library that is compliant to net461.
Quoting for the .NET Core 2/Standard 2.0 announcement with links:
.NET Core 2.0 is able to freely reference libraries that have been built for .NET Framework up to version 4.6.1
However, some libraries may fail at run time if they try to use API methods that aren't available on .NET Core
Reference: .NET Core App target .NET framework 4.5.2 on Linux
A need to use third-party .NET libraries or NuGet packages not available for .NET Core
So only in cases where the libraries or NuGet packages use technologies that aren't available in .NET Standard/.NET Core, you need to use the .NET Framework.
Reference: Choosing between .NET Core and .NET Framework for server apps
You can now reference .NET Framework libraries from .NET Standard libraries using Visual Studio 2017 15.3. This feature helps you migrate .NET Framework code to .NET Standard or .NET Core over time (start with binaries and then move to source). It is also useful in the case that the source code is no longer accessible or is lost for a .NET Framework library, enabling it to be still be used in new scenarios.
Reference: Announcing .NET Core 2.0
Yes, we are currently attempting the same thing. The trick is to make sure that you are supporting the same .NET frameworks. Inside your project.json file, make sure the framework matches the framework of the project you wish to include. For example:
"frameworks": {
"net46": { --This line here <<<<
"dependencies": {
"DomainModel": {
"target": "project"
},
"Models": {
"target": "project"
}
}
}
},
FYI: You might need to change the framework of your .NET Core or your older projects to achieve this. .NET Core can be changed just by editing the project.json file as seen above. You can so the same in .NET projects by right clicking the project and opening properties. Change the framework level there.
Once you have matched the two project frameworks then you should be able to include them. Good Luck!
We delayed migrations as long as could as it seemed daunting as first. But we got an insistent client who wanted to migrate ASAP.
So we migrated their Fintech Web App developed on .NET Framework 4.8 Web Forms to .NET 6 Razor Page. Our team scoured though hundreds of online resources & spoke to Microsoft Tech Support before we started the project. Hope the high-level walkthrough of our journey help you plan your migrations.
Our .NET Framework Website consisted of 1 .NET Web Forms project and 12 Class Libraries.
Here is how we did it.
Refactored the .NET Framework 4.8 Web Forms code
We ensured that the Web Forms code behind did not have a single line of service or business logic code. When we did find some business logic code in the web forms code behind, we refactored it, by moving it to the class libraries.
Created new .NET Standard projects
We created a new .Standard 2.0 Class library project for every .NET Framework 4.8 Class Library. If the original project was called "FintechProjectName.StockMarketClient", we named the .NET standard project "FintechProjectName.StockMarketClient.Standard".
Copied all files from .NET framework to .NET standard
We copied all the class files from .NET framework to .NET standard projects. We then removed all the .NET framework class libraries from the solution and added references to the new class libraries. All projects compiled on the 1st try itself and all our test cases too passed with minor changes.
Create new .NET 6 Web App Project
We created a new .NET 6 Web App Project. We had to entirely redo the front-end as there is no direct path for migrating Web Forms to Razor Pages. This was the only project which took us about 1 month to migrate.
Reference .NET standard class libraries in the new .NET 6 website
We copied all the .NET Standard libraries to this new solution containing the Razor Pages web site. Added the references and got it to work.
Move from .NET Standard to .NET 6 class libraries
Once the new website was up and running, with all test cases passed, we did the last step in the process which was the simplest. Created .NET 6 class library projects for each of the .NET standard libraries and named the projects appropriately. Copied all class files from .NET standard projects to their corresponding .NET 6 projects. Then we removed the .NET Standard libraries and added references to the new class libraries.
Overall project timelines were about a month and a half, most of it spend on Razor Pages implementation using the same html design.
Note:
If you are using any 3rd party library which does not have a .NET standard or .NET 5 version, then you are out of luck. You will need to find a replacement nuget package and recode your application to use this new library.
In my case with .net6 referencing framework 4.8 library ( both winforms), the trick seems to be to add the reference to the framework dll as a shared reference.

Is there a way to add and start a .Net Core 2.0 REST server inside a .Net Framework 4.5.2 (or .Net Framework 4.6.1 or .Net Standard 2.0) application?

Issue
Hi,
I am currently working on implementing a RESTful API in C# using ASP.net Core 2.0 in Visual Studio 2017 (running only via Kestrel, therefore no IIS).
Everything works pretty well, no issues there. The thing is that I now need to integrate and start this REST Server in another project (The REST server being only one of many functionalities that need to be executed at the same time, using a "bootstrap"). My issue here is that the latter project targets .Net Framework 4.5.2 whereas the REST server targets .Net Core 2.0. Thus, when I add the REST server to the references of my bootstrap application, I encounter a couple of errors saying that some of the Nuget packages target the wrong framework.
Solutions I tried
I searched over Google but most of the issues I found were people trying to do the other way round, i.e. adding a .Net Framework-targeted project in a .Net Core application.
The way I understood this .Net implementation support table, is that a .Net standard 2.0 project can support a .Net Core 2.0 project (I am probably wrong).
I tried a couple of things to make it work (which, spoiler alert, obviously and unfortunately did not work as I wouldn't be asking your help) :
Made the boostrap application target .Net Standard 2.0
Made the boostrap application target .Net Framework 4.6.1
Made the REST server application target .Net Standard 2.0 (which it of course didn't work, but I was kind of desperate..)
I made these target change by modifying the .csproj files.
I don't have the exact error codes because I reverted my changes a while back but they all were about projects not targeting the same framework.
So, in a tl;dr manner, what I am asking is :
Is there a way to add a .net Core 2.0 REST server inside a .Net Framework 4.5.2 (or 4.6.1 and higher/ or .Net Standard 2.0) project to start the server inside the application ?
Apologies for any english mistake as it is not my native language.
Don't hesitate to ask more info on my problem if I wasn't clear enough and thanks for the help !

Are .NET Core projects referencing PCLs cross-platform?

I have a .NET Core (ASP.NET Core) project created using Visual Studio 2017 RC (MSBuild).
I also have an old F# project library (traditional .NET Framework Library) that compiles to a dll file. I want to use it in said ASP.NET Core project.
To do that, I added a project reference in the ASP.NET Core project, opened the namespace, and made a few function calls in my controllers; it works perfectly when running the ASP.NET Core server using ISS from VS.
My question is, will this arrangement work if I want to deploy to linux (Ubuntu)? Or does using external PCLs/dlls from .NET Core instantly make it windows-only?
Note that I didn't have to add .NET Framework as a target framework in my csproj (it's MSBuild Core), it just worked.
Since your F# project targets the .NET Framework it will not run cross platform. If you modify your F# project to target the .NET Standard library it will. Here is a video by Immo Landwerth explaining how the .NET Standard Library works.
You should be able to just to reference the .NET standard library and not have to change anything. However the current version, which is 1.6, is missing a lot of API's from .NET Framework. This is fixed in 2.0. Infact since your using .NET Core 1.1 I think you are already using 2.0, but I'm not certain. Here is another video by Immo explaining how it should work.
That being said, I'm not sure what the F# support is like with .NET Standard.

ASP.net 5 preview templates are missed in Visual Studio 2015

I have installed Visual Studio 2015 update 3 and have installed the latest Web Essentials update and also have installed DotnetCore version. But when I create a new asp.net project, only asp 4 templates like in the image are available
create form image
First of all, there is no ASP.NET 5 anymore. It has officially been renamed to ASP.NET Core 1.0.
You seem to have missed that announcement, which would have made the selections in Visual Studio more obvious. When you choose File > New Project..., you get to a dialog that gives you a choice to go with ASP.NET Web Application (.NET Framework), ASP.NET Core Web Application (.NET Core) or ASP.NET Core Web Application (.NET Framework). This is the dialog before the one you have posted a screenshot of.
NOTE: In order to see all 3 of these options, you need to choose at least .NET Framework 4.5 from the dropdown.
The last two options are for the new ASP.NET Core 1.0 framework. The first of which is to run on the .NET Core library (cross-platform) and the last which is for the .NET Framework 4.6.1 library (which is not cross-platform).
Of course, if you choose ASP.NET Web Application (.NET Framework) , you get a regular MVC 5 or Web API 2 application.

Which class library type do I use with a Core 1.0 RC2 (.NET Framework) Web App

In ASP.NET Core RC2 Microsoft split the Core web application into two separate templates:
ASP.NET Web Application (.NET Framework)
and
ASP.NET Web Application (.NET Core)
I am planning on developing an app that is net 451 only. If I go the (.NET Framework) path. What type of class libraries should I be using? I assumed Class Library (.NET Core), but when I tried adding reference from a project with the (.NET Framework Template) it says it can't add reference to .NET Standard.
Maybe I shouldn't be using the .NET Framework template. The main reason why I feel like I should be is because I do not want to have to deal with developing for the other operating systems and not having access to certain packages like email and transactionscope, etc..
If you set your class library to target net451 also it will work.
Change project.json in class library project as follows...
"frameworks": {
"net451": { }
}
As I understand it, .NET Standard can reference .NET Core libraries, but .NET Core cannot reference .NET Standard libraries.
So, it comes down to the end-use of your application. If it's only going to run (or be hosted) on Windows, then use the larger, more established .NET Standard for the application (although you can choose to put common code in .NET Core projects in the same solution for future cross-platform re-use). However, if there's a requirement to run/host it on another platform (Linux, Mac), then you'll have to use the younger .NET Core.

Categories