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?
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With