以编程方式获取dotnet核心运行时的当前运行版本 [英] Programmatically get current running version of dotnet core runtime

查看:285
本文介绍了以编程方式获取dotnet核心运行时的当前运行版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个aspnetcore Web应用程序,我想写它的当前版本,以及启动时正在运行的dotnet core运行时版本.

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.

我想这样做,因为我的Web应用程序可以在云中的各种VM上运行,并且我希望能够查看所有日志中的日志,并确保它们都在相同的dotnet核心运行时中运行版本.

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

获取我的应用程序版本很容易(仅是汇编版本),但是,我找不到获取dotnet运行时版本的方法吗?

Getting my app version is easy (just assembly version), However, I can't find a way to get the dotnet runtime version?

我看到了各种各样的东西,它们引用了 Microsoft.DotNet.PlatformAbstractions nuget软件包,但这似乎根本没有给我dotnet运行时版本.

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.

还有System.Environment.Version,但是报告4.0.30319.42000,它是,而不是dotnet核心版本.

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.

推荐答案

自.NET Core 3.0起,您可以直接调用改进的API来获取此类信息.

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

查看此问题

这篇关于以编程方式获取dotnet核心运行时的当前运行版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆