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?
12 Answers
Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion; 2Add 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;