Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve Product Version?

Is there a way to retrieve the product version of an ASP.NET 5 web application?

This is what I have in my project.json:

"version": "4.0.0-alpha1"

How would I be able to retrieve this from within the application? I used to be able to do this on older ASP.NET versions:

System.Reflection.Assembly.GetExecutingAssembly().GetName().Version

However, now it just gives me 0.0.0.0 all the time. Any ideas?

like image 345
painiyff Avatar asked Jun 07 '26 01:06

painiyff


1 Answers

Add a reference to System.Reflection in your project.json file if you don't already have one.

"dependencies": {
    "System.Reflection": "4.1.0-beta-23516" // Current version at time of posting
}

Then, you can get the value from the AssemblyInformationalVersionAttribute InformationalVersion property.

private static string GetRuntimeVersion() =>
        typeof(SomeClassInYourAssembly)
            .GetTypeInfo()
            .Assembly
            .GetCustomAttribute<AssemblyInformationalVersionAttribute>()
            .InformationalVersion;
like image 188
Will Ray Avatar answered Jun 10 '26 19:06

Will Ray