Reputation: 1120
I know that all Dot Net Core projects get marked with a package version tag that appears in the CSProj file, like this:
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<StartupObject>MY.Program</StartupObject>
<TypeScriptToolsVersion>2.5</TypeScriptToolsVersion>
<AssemblyName>MY.PCA</AssemblyName>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Version>1.2.0</Version>
</PropertyGroup>
Is there a way to get access to that Version number field at Runtime? Namely in the Startup routines found in Startup.cs?
Upvotes: 2
Views: 3398
Reputation: 353
Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion;
Upvotes: 1
Reputation: 49779
Add Microsoft.Extensions.PlatformAbstractions package as dependency and then use ApplicationEnvironment.ApplicationVersion
property to get the version:
// using using Microsoft.Extensions.PlatformAbstractions;
ApplicationEnvironment app = PlatformServices.Default.Application;
string version = app.ApplicationVersion;
Upvotes: 2