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.
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