Thursday, May 10, 2018

Get Assembly Version in .NET Core?


Most enterprise application soon or latter, have a requirement to trace out the version of a currently running application. This post shows few example, which demonstrates how to do this in .NET Core.

 var ver = Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion;

           
 var attrs = typeof(Startup.GetTypeInfo() .Assembly.GetCustomAttributes(); 

var runtimeVersion = typeof(Startup)
.GetTypeInfo()
.Assembly
.GetCustomAttribute<AssemblyFileVersionAttribute>();  
var tokens = runtimeVersion.Version.Split('.');  
m_Version = new Version(runtimeVersion.Version)

No comments: