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

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

问题描述

我有一个 aspnetcore 网络应用程序,我希望它编写它的当前版本,以及它在启动时运行的 dotnet 核心运行时版本.

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.

我想这样做,因为我的 webapp 在云中的各种 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.

我想要的是这样的.

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 4.6+ 框架版本,而不是 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天全站免登陆