What is Metapackage in C# Asp.net Core?


It is known that Microsoft.AspNetCore package is one of the packages added to many ASP.NET Core templates.

The Microsoft.AspNetCore package is repeatedly included as one of the usual project dependencies when opening a new ASP.NET Core project. It delivers many of the crucial packages to position up a basic ASP.NET Core application.

Though, this package does not contain any actual dlls or code itself, it merely contains a series of dependencies on additional packages. By adding this package to your project, you bring in all the relevant packages along with their dlls on which it depends and it is called a metapackage.

Specifically, the packages it lists are −

Microsoft.AspNetCore.Diagnostics
Microsoft.AspNetCore.Hosting
Microsoft.AspNetCore.Routing
Microsoft.AspNetCore.Server.IISIntegration
Microsoft.AspNetCore.Server.Kestrel
Microsoft.Extensions.Configuration.EnvironmentVariables
Microsoft.Extensions.Configuration.FileExtensions
Microsoft.Extensions.Configuration.Json
Microsoft.Extensions.Logging
Microsoft.Extensions.Logging.Console
Microsoft.Extensions.Options.ConfigurationExtensions
NETStandard.Library

The versions of these packages you will receive depends on which version of the Microsoft.AspNetCore package you install.

These dependencies deliver the primary basic libraries for setting up a basic ASP.NET Core server that uses the Kestrel web server and includes IIS Integration.

In terms of the application itself, with the help of this package alone you can load application settings and environment variables into configuration, use the IOptions interface, and configure logging to the console.

For middleware, only the Microsoft.AspNetCore.Diagnostics package is included, which would allow adding middleware such as the ExceptionHandlerMiddleware, the DeveloperExceptionPageMiddleware and the StatusCodePagesMiddleware.

To complete an application, we cannot use only Metapackage because it does not provide sufficient controls but we can use Microsoft.AspNetCore.Mvc or Microsoft.AspNetCore.MvcCore package to add MVC capabilities to our application, and also some other packages would be needed.

The metapackage just try to use a number of packages that can be applied to many applications so that we don’t need to load more dependencies but it actual does not do that because it requires other packages as well. Thus, if the number of packages is large then the dependencies increases which impacts the real use of metapackage. For example, one of the dependencies on which the Microsoft.AspNetCore depends is the NETStandard.Library package, which is also a metapackage and hence the dependencies increases.

Updated on: 25-Sep-2020

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements