I have an aspnetcore webapp and I'd like it to write it's current version, as well as the dotnet core runtime version that it's running on to it's log when it starts up.
I'd like to do this as my webapp runs on various VM's in the cloud and I'd like to be able to look at the logs from all of them and make sure they're all running the same dotnet core runtime version.
What I want is something like this.
App version 1.0.1 running on dotnet 2.0.6
Getting my app version is easy (just assembly version), However, I can't find a way to get the dotnet runtime version?
I've seen various things referencing the Microsoft.DotNet.PlatformAbstractions nuget package, however this doesn't appear to give me the dotnet runtime version at all.
There's also System.Environment.Version, but that reports 4.0.30319.42000
which is the "desktop" dotnet 4.6+ framework version, not the dotnet core version.
You can see both the SDK versions and runtime versions with the command dotnet --info . You'll also get other environmental related information, such as the operating system version and runtime identifier (RID).
Finding the version by using the Runtime menu On the Runtime menu, select About. The version is displayed in the Version field in the About dialog box.
NET releases in odd-numbered years are Long-term Support (LTS) releases and are supported for three years. Releases in even-numbered years are Short-term Support (STS) releases and are supported for 18 months.
Since .NET Core 3.0, you can directly call improved API to get such information.
var netCoreVer = System.Environment.Version; // 3.0.0
var runtimeVer = System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription; // .NET Core 3.0.0-preview4.19113.15
Check out this issue
For a detailed description you can find the original article here: https://learn.microsoft.com/en-us/dotnet/framework/migration-guide/how-to-determine-which-versions-are-installed
Along with the original github comment chain here: https://github.com/dotnet/BenchmarkDotNet/issues/448
public static string GetNetCoreVersion() {
var assembly = typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly;
var assemblyPath = assembly.CodeBase.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);
int netCoreAppIndex = Array.IndexOf(assemblyPath, "Microsoft.NETCore.App");
if (netCoreAppIndex > 0 && netCoreAppIndex < assemblyPath.Length - 2)
return assemblyPath[netCoreAppIndex + 1];
return null;
}
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