AspNetCore.VersionInfo is a library to expose information about assembly versions used in your web application. In particular there are three endpoints, which returns:
- a JSON-formatted data (/version/json)
- an HTML user-friendly page (/version/html)
- a nice badge image (/version/badge)
Library offers some in-bundle providers to capture versions information, such as the version of entry assembly or the version of the common language runtime. A typical JSON output is:
{
"RuntimeInformation.FrameworkDescription":".NET 6.0.8",
"EntryAssemblyVersion":"2.5.0.0",
...
}
Moreover it is possible create a specific class to collect additional data as described in Providers section.
This library currently targets net6.0
Prerelease packages are on GH Packages
Release packages are on Nuget
URL | |
---|---|
Windows Web App | https://aspnetcoreversioninfo-demo.azurewebsites.net |
Windows HTML Endpoint | /version/html |
Windows JSON Endpoint | /version/json |
Windows Badge Endpoint | |
Linux Web App | https://aspnetcoreversioninfo-linux-demo.azurewebsites.net |
Linux HTML Endpoint | /version/html |
Linux JSON Endpoint | /version/json |
Linux Badge Endpoint |
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddVersionInfo()
.With<ClrVersionProvider>()
.With<AssemblyVersionProvider>();
}
public void Configure(IApplicationBuilder app)
{
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapVersionInfo();
});
}
}
Library is based on following types:
- Providers, that read information and return data in a dictionary
- Collector, that aggregates all data from providers and exposes to endpoints.
A Collector implementation is already included in AspNetCore.VersionInfo package, and usually its default implementation is valid for all scenarios.
Instead, in order to enrich data gathered from library, multiple custom providers could be developed, implementing custom classes inherited from IInfoProvider
interface.
To show providers' information, they have to be configured in ConfigureServices
declaration, using .With<IInfoProvider>
extension method.
AspNetCore.VersionInfo package includes following providers:
Provider | Keys | Description |
---|---|---|
AssemblyVersionProvider | EntryAssembly EntryAssemblyFullName EntryAssemblyLocation EntryAssemblyDirectoryPath EntryAssemblyFileVersion EntryAssemblyClrVersion EntryAssemblyCreationDate EntryAssemblyLastModifiedDate |
Version and main properties of entry assembly |
ClrVersionProvider | RuntimeInformation.FrameworkDescription RuntimeInformation.OsDescription RuntimeInformation.OsArchitecture RuntimeInformation.ProcessArchitecture RuntimeInformation.RuntimeIdentifier |
Version of the common language runtime and .NET installation on which the app is running |
AppDomainAssembliesVersionProvider | <AssemblyName> |
Version of assemblies loaded in App Domain |
EnvironmentProvider | Environment.Uptime Environment.OSVersion Environment.IsOsWindows Environment.Is64BitOperatingSystem Environment.Is64BitProcess Environment.ProcessorCount Environment.MachineName Environment.SystemDirectory Environment.WorkingDirectory Environment.CommandLine Environment.DotNetVersion |
Environment properties |
EnvironmentVariablesProvider | <EnvironmentVariableName> -<EnvironmentVariableValue> |
Environment variables |
MapVersionInfo
extension method accepts an optional VersionInfoOptions
argument to change default URLs:
public void Configure(IApplicationBuilder app)
{
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapVersionInfo(o =>
{
o.HtmlPath = CUSTOM_HTML_URL;
o.ApiPath = CUSTOM_JSON_URL;
});
});
}
Badge image can be obtained with url
/version/badge/{versionInfoId}
where {versionInfoId}
is a key returned by providers.
Moreover endpoint accepts following parameters in querystring:
label
: it's the name to show in the imageicon
: the source type and slug for the icon separated by two underscore characters (__
) such assimpleicons__azure
. In this version only Simple Icons type is supported; you can find a list of slugs here. Icon color is always white.color
: a string as defined in the colors table or a custom colors in hexadecimal, RGB, HSL.
Color | String |
---|---|
BrightGreen | |
Green | |
Yellow | |
YellowGreen | |
Orange | |
Red | |
Blue | |
Gray | |
LightGray |
Name | Notes | Repository |
---|---|---|
Basic | Simple .NET 6 WebApplication with built-in endpoints (published in demo site) | πΎ |
CustomOptions | WebApplication with custom configuration for endpoint URLs | πΎ |
Minimal | WebApplication using Minimal API | πΎ |
Authentication | WebApplication leverages the ASP.NET Core Authentication/Authorization features to easily restrict access | πΎ |
In order to enable AspNetCore.VersionInfo only in the development environment, change Configure
method
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
...
app.UseEndpoints(endpoints =>
{
if (env.IsDevelopment())
{
endpoints.MapVersionInfo();
}
});
...
}
public void ConfigureServices(IServiceCollection services)
{
...
services.AddAuthorization(cfg =>
{
cfg.AddPolicy(name: Constants.VERSIONINFO_USER_POLICY, cfgPolicy =>
{
cfgPolicy.AddRequirements().RequireAuthenticatedUser();
cfgPolicy.AddAuthenticationSchemes(Constants.COOKIE_SCHEME);
});
});
...
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
...
app.UseEndpoints(endpoints =>
{
endpoints.MapVersionInfo().RequireAuthorization(Constants.VERSIONINFO_USER_POLICY); ;
});
...
}
For more information, you can inspect Authentication example.
AspNetCore.VersionInfo is Apache-2.0 licensed