Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What <FrameworkReference Include="Microsoft.AspNetCore.App" /> is actually do in .net core 3+?

Recently, I've read about Use the ASP.NET Core shared framework and I'm wondering:

  1. How is it working under the hood?
  2. Are there any drawbacks or caveats that I should take into account when adding <FrameworkReference Include="Microsoft.AspNetCore.App" />?

For example, I'd created a simple console application and published it with self-hosted options. The output size was on 20mb greater with <FrameworkReference Include="Microsoft.AspNetCore.App" / even If I don't explicitly use any of Microsoft.AspNetCore packages

like image 851
Yaroslav Bres Avatar asked Oct 22 '20 08:10

Yaroslav Bres


People also ask

What does .NET Core include?

NET Core application side by side with your application seamlessly. It is a general-purpose development platform that consists of several components. These include the managed compilers, the runtime, and the base class libraries. It also includes many application models, such as the ASP.NET Core.

What is Microsoft ASP.NET Core razor design?

Razor is a markup syntax for adding server-side logic to web pages. This package contains MSBuild support for Razor. Learn more about Target Frameworks and . NET Standard.

What is Microsoft ASP.NET Core builder?

WebApplication Class (Microsoft.AspNetCore.Builder) The web application used to configure the HTTP pipeline, and routes.


1 Answers

The shared framework is a collection of assemblies that is included in the runtime and as such does not need to be resolved individually through NuGet. You can think of it as a NuGet package though, because the handling is very similar. The primary difference of course is that it doesn’t need to be downloaded from NuGet because it is available locally with the runtime.

Since it is distributed with the runtime, that also means that you cannot reference a specific version of it. Instead, you always get the version that is included in the available version of the runtime. This has the benefit that the contents will automatically update when the runtime is updated, so your application that depends on one of the shared frameworks will also just roll forward at runtime.

  1. Attempting to answer that in detail is out of the scope of a Stack Overflow answer since this is some deep MSBuild logic. If you are interested to find out, you can checkout the dotnet/sdk repo though which contains everything that makes the Microsoft.NET.Sdk project SDK and its subtypes work, including the FrameworkReference implementation.

  2. First of all you should know that there is no way to use e.g. ASP.NET Core without using that framework reference. So it’s not like you have much of a choice. Most of the time, you won’t be adding the framework reference yourself though; ASP.NET Core applications use the Microsoft.NET.Sdk.Web project SDK which already includes the framework reference by default. You will only need to add the framework reference yourself if you want to add ASP.NET Core references in a non-Web project (for example in a class library for ASP.NET Core).

    Apart from that, there aren’t many things you will have to keep in mind though. Just remember not to use a version and keep your SDK and runtime updated to make sure that you have all the latest security patches.

like image 182
poke Avatar answered Oct 11 '22 18:10

poke