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?

1

2 Answers

Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion; 
2

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; 

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy