Helper library for ASP.NET Core 5 - NuGet packages not available? - asp.net-core

I'm writing a helper library for ASP.NET Core 5 (with .NET 5) and I need some APIs from the package Microsoft.AspNetCore.Server.Kestrel.Core. However, the package is only available in version 2.2 - not version 5.
Is ASP.NET Core no longer distributed via NuGet? And if so, how does one get the APIs with ASP.NET Core 5.
Side note: I found that I could use Microsoft.NET.Sdk.Web as SDK for the project but I'm unsure whether this is a valid/good/correct approach when writing a library.

Is ASP.NET Core no longer distributed via NuGet? And if so, how does one get the APIs with ASP.NET Core 5.
That's correct. The core of ASP.NET Core (no pun intended...) ships with .NET Core >= 3.0 as a shared framework. You can add a single FrameworkReference to your nuget package to pull this in. See https://learn.microsoft.com/en-us/aspnet/core/migration/22-to-30?view=aspnetcore-5.0&tabs=visual-studio#migrate-libraries-via-multi-targeting for more information.
Some background can be found here https://github.com/dotnet/aspnetcore/issues/3756

Related

ASP.NET Core Web Application with .NET Framework, I want to switch the target to .NET Core

I'm trying to change ASP.NET Core web application with .NET Framework as a target framework to use .NET Core 3.1.X
I try changing the target framework in the project file (.csproj), I encounter dependency issues, dependency conflict....
Is there any straightforward method to solve this issue?
Before you start your migration, you should know there’s several difference between .net framework and .net core, so please follow the official document to do some Pre-Migration steps.
Then you can follow this official document to migrate your application from framework to .net core 3.1.
Since your ideal .net core version is 3.1, still I suggest you can try to use .net 6. Also, you can use this upgrade tool to reach your goal. In fact, using this upgrade assistant is a batter choice than you doing it by yourself. Even if you are insisting using .net core 3.1, you can use this assistant to upgrade your version to 6 first then change it to 3.1.
Note:
Before you start your migration, please make a backup of your original project. That's because some packages in .net framework may be no longer available in .net core. So if there're some errors occur, you can go back to the original one.

It's very confusing.. I was creating .net core web application and can see .NetFramework with .NetCore support

I was creating .net core web application and can see .NetFramework with .NetCore support. But I didn't choose .Net Standard. I don't understand. Please see the image asp.net core web application
This is Microsoft naming at work here. 😁 There are two dotnet frameworks: the "full" framework, which you selected, and the dotnet core framework.
Before dotnet core and all it's optimized, multiplatform goodness, there was the dotnet framework (refered to as the legacy or full framework). This is the predecessor of dotnet core. This full framework runs only on Windows and the computer it runs on needs the dotnet framework runtime.
Do not worry, the "full" in full framework comes from the transition period between the old dotnet framework and dotnet core. When dotnet core was version 1.0, it did not have all the functionality of today. So some developers called it the full framework (which had everything you needed to run your application) and the newer dotnet core framework which had only the basics.
You can see if you are running the legacy framework if there is the <TargetFramework>netXXX</TargetFramework> present in your solution/project file. The lastest version of the full dotnet framework is 4.8 (net48).
After that it switched to dotnet core 1.0 - 3.1. I'm not entirely sure how that's referenced in the solution/project files.
As a last remark, Microsoft had a great naming idea: the next version of dotnet core is named dotnet 5. They want to get back to the original name with this next version. Do keep in mind that you cannot easily upgrade from dotnet 4.X to dotnet 5. The day to day code looks very much alike, but the underlying engine is completely rewritten.
As far as I know, before .net core 3.0, asp.net core is support on .net framework. This is the reason why you could create .net core 2.1 on the .net framework.
But after 3.0, asp.net core not support .net framework. You could only create it on .net core framework.
More details, you could refer to this article and this github issue.

What will happen to the Microsoft.AspNetCore.* namespace in ASP.NET 5.0?

.NET 5.0 will replace .NET Core 3.x when it is released in November—and, thus, ASP.NET 5.0 will replace ASP.NET Core 3.x.
Edit: This question is based on a fundamentally incorrect assumption. While the next version of .NET Core will, in fact, be .NET 5.0, the next version of ASP.NET Core will be ASP.NET Core 5.0. See the answers from #Camilo-Terevinto and #omajid for details.
Despite this, as of Preview 8 (8.20414.8), packages, assemblies, and namespaces still contain AspNetCore in their names. For example, see the following NuGet packages:
Microsoft.AspNetCore.Http.Features
Microsoft.AspNetCore.Authorization
Microsoft.AspNetCore.DataProtection
Microsoft.AspNetCore.Razor.Language
If you go to the documentation for e.g. the Microsoft.AspNetCore.Http.Features namespace on learn.microsoft.com, however, you'll be redirected back to the ASP.NET Core 3.1 documentation with the warning:
The requested page is not available for ASP.NET Core 5.0 Preview. You have been redirected to the newest product version this page is available for.
Question: Do we have any evidence of what these packages, assemblies, and namespaces will be named in the .NET 5.0 release? Will they remain Microsoft.AspNetCore for backward compatibility, as the current namespaces suggest? Will they become Microsoft.AspNet for consistency with the product name, as the documentation suggests? Or does this remain TBD?
Background: Like other developers, I am working on the .NET 5.0 version of an open source library, and we aim to follow the same naming conventions as the underlying framework for the sake of familiarity, discovery, and consistency.
and, thus, ASP.NET 5.0 will replace ASP.NET Core 3.x.
That is not accurate, ASP.NET Core 5.0 will replace ASP.NET Core 3.x. The moniker that will change is .NET Core to .NET. Migration guide ASP.NET Core 3.x to ASP.NET Core 5.0.
Basically:
.NET Framework 4.8 -> .NET 5
.NET Core 3.1 -> .NET 5
ASP.NET Core 3.1 -> ASP.NET Core 5
thus, ASP.NET 5.0 will replace ASP.NET Core 3.x.
No, it won't. It's an unfortunate point of confusion, but it's not true.
Let me quote David Fowler, who is one of the ASP.NET Core architects:
There's no plan to change asp.net core to asp.net.
.NET Core becomes .NET 5, but ASP.NET Core stays as ASP.NET Core.

What packages are needed at a minimum for ASP.NET Core MVC (3.1)?

I created a default (template) ASP.NET Core MVC 3.1 application using Windows 10/Visual Studio 2019. (background: I am looking to re-write/convert an ASP.NET MVC 5 web site to Core 3 MVC).
After creating the default ASP.NET Core MVC solution (which I can compile/run), I noticed in NuGet, that no packages are installed by default. I have the following questions:
1) How is it that the app compiles/runs, even though no packages, not even Core MVC, are shown in Packages installed?
2) For re-writing my app/web site, I will be using MVC, Razor Views, EF Core (using SQL Server, database first approach). When searching in NuGet, there are many related Microsoft packages. What are the minimum packages I must install via NuGet (to get started)?
Have you tried looking at which SDK your project file references when you create an empty ASP.NET Core Web Application?
It's Microsoft.NET.Sdk.Web. This inherits Microsoft.AspNetCore.App, and that metapackage references a whole lot of other packages, amongst others:
Microsoft.AspNetCore.Mvc (>= 2.2.0 && < 2.3.0)
Microsoft.AspNetCore.Mvc.Razor (>= 2.2.0 && < 2.3.0)
Microsoft.EntityFrameworkCore (>= 2.2.6 && < 2.3.0)
So expand the SDKs node under your project, not the Packages node.
In your csproj file, you'll note at the top that the <Project> tag lists an SDK; the SDK handles inclusion of the ASP NET Core supported packages.
From ASP.NET Core Web SDK:
Features enabled by using the Web SDK:
Projects targeting .NET Core 3.0 or later implicitly reference:
The ASP.NET Core shared framework.
Analyzers designed for building ASP.NET Core apps.
From Microsoft.AspNetCore.App for ASP.NET Core:
Projects that target the Microsoft.NET.Sdk.Web SDK implicitly
reference the Microsoft.AspNetCore.App framework.
The ASP.NET Core shared framework:
Doesn't include third-party dependencies.
Includes all supported packages by the ASP.NET Core team.
In order to get started with Entity Framework Core and SQL Server, you can install the specific provider for SQL Server -- Microsoft.EntityFrameworkCore.SqlServer should get you there and cascade the dependencies.
From Installing Entity Framework Core:
To add EF Core to an application, install the NuGet package for the
database provider you want to use.
If you're building an ASP.NET Core application, you don't need to
install the in-memory and SQL Server providers. Those providers are
included in current versions of ASP.NET Core, alongside the EF Core
runtime.

.NET Core vs ASP.NET Core

What exactly is the difference between .NET Core and ASP.NET Core?
Are they mutually exclusive? I heard ASP.NET Core is built on .NET Core, but it can also be built on the full .NET framework.
So what exactly is ASP.NET Core?
Update 2020: Do note that ASP.NET Core 3 and higher now depend on .NET Core and can no longer be used on .NET Framework. The below description is for ASP.NET Core 1.x-2.x; the layer separation still holds true for ASP.NET Core 3.0 but the ASP.NET Core layer can no longer be used on top of .NET Framework in 3.0+.
.NET Core is a runtime. It can execute applications that are built for it.
ASP.NET Core is a collection of libraries that form a Framework for building web applications.
ASP.NET Core libraries can be used on both .NET Core and the "Full .NET Framework" (which has shipped with windows for many years).
The confusing part is that an application using the libraries and tools of ASP.NET Core is usually referred to as "ASP.NET Core Application", which in theory doesn't say if it is built for .NET Core or .NET Framework. So an "ASP.NET Core Application" is also a ".NET Core Application" or a ".NET Framework Application".
This image shows the relation of the involved technologies (taken from this blog post)
Here you can see that ASP.NET Core is built "on top of" both .NET Framework and .NET Core, while "ASP.NET" (now often referred to as "classic ASP.NET") is .NET Framework only.
ASP.NET Core using .NET Core - all dependencies are self-contained, can use most NuGet packages, can't use Windows-specific packages, can execute on Windows, Linux, and Mac.
ASP.NET Core using .NET Framework - most dependencies are self-contained, only executes on Windows, will have access to Windows-specific NuGet packages, needs the .NET framework version which is targeted installed on the machine.
ASP.NET Core is one of the workloads supported by .NET Core.
From .NET Core guide:
By itself, .NET Core includes a single application model -- console apps -- which is useful for tools, local services and text-based games. Additional application models have been built on top of .NET Core to extend its functionality, such as:
ASP.NET Core
Windows 10 Universal Windows Platform (UWP)
Xamarin.Forms
The .NET Framework is on its last release. There will not be another one after 4.8. Microsoft will continue with .NET Core. From this time you should prefer .NET Core on your projects.
Official update (source):
.NET 5 is the next major release of .NET Core following 3.1. We named this new release .NET 5 instead of .NET Core 4 for two reasons:
We skipped version numbers 4.x to avoid confusion with .NET Framework 4.x.
We dropped "Core" from the name to emphasize that this is the main implementation of .NET going forward. .NET 5 supports more types of apps and more platforms than .NET Core or .NET Framework.
ASP.NET Core 5.0 is based on .NET 5 but retains the name "Core" to avoid confusing it with ASP.NET MVC 5. Likewise, Entity Framework Core 5.0 retains the name "Core" to avoid confusing it with Entity Framework 5 and 6.
.NET Core is the next evolution of the .NET Framework, that allows Microsoft technology to be hosted on other OS platforms, rather than Windows.
ASP.NET is the web framework provided by Microsoft for building:
server-side rendered web pages/websites
server-side components for SPAs
MVC-fashion apps
web services/web APIs/microservices
ASP.NET runs only on Windows platforms.
Since .NET Core was created to provide the capability of running Microsoft tech on top of Linux/macOS, it implies that ASP.NET Core is the evolution of ASP.NET in the direction of multi-platform support.
In conclusion:
ASP.NET Core runs on both .NET Core and .NET 5.0, on top of multiple OS platforms: Windows, Linux & macOS.
ASP.NET 4.x (ASP.NET/ASP.NET MVC) runs on the .NET Framework only, on top of Windows OS.