简体   繁体   English

如何从 .NET 框架应用程序以编程方式检查安装在我的机器上的 .NET Core Runtime 版本?

[英]How to programmatically check the .NET Core Runtime version installed on my machine from a .NET Framework app?

I am writing an application in C#.我正在 C# 中编写一个应用程序。 The application is a console application targeting .NET 4.7.该应用程序是针对 .NET 4.7 的控制台应用程序。 From that application I want to programmatically check if .NET Core 3.1.300 runtime is installed.从该应用程序中,我想以编程方式检查是否安装了 .NET Core 3.1.300 运行时。 If not then I want to install it.如果没有,那么我想安装它。 How to do that?怎么做? So far I haven't found any API to check the installed .net core runtime.到目前为止,我还没有找到任何 API 来检查已安装的 .net 核心运行时。

To save you the trouble you have to query these locations in the registry:为了省去您必须在注册表中查询这些位置的麻烦:

For x64 versions对于 x64 版本

HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\dotnet\Setup\InstalledVersions\x64\sharedfx\Microsoft.NETCore.App

For x86 versions对于 x86 版本

HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\dotnet\Setup\InstalledVersions\x86\sharedfx\Microsoft.NETCore.App

This may change in the future but from what i've seen and from my machine all the versions are logged in these locations.这可能会在未来发生变化,但从我所看到的和我的机器来看,所有版本都记录在这些位置。

Regarding Linux关于 Linux

from the docs link that Olivier Rogier suggested you can check for these folders:从 Olivier Rogier 建议的文档链接中,您可以检查这些文件夹:

dotnet executable /home/user/share/dotnet/dotnet dotnet 可执行文件 /home/user/share/dotnet/dotnet

.NET SDK /home/user/share/dotnet/sdk/{version}/ .NET SDK /home/user/share/dotnet/sdk/{version}/

.NET Runtime /home/user/share/dotnet/shared/{runtime-type}/{version}/ .NET 运行时 /home/user/share/dotnet/shared/{runtime-type}/{version}/

Yes.是的。 From .Net Core 3 you can use:.Net Core 3 ,您可以使用:

var netCoreVer = System.Environment.Version; 
var runtimeVer = System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription; 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从WinForms应用程序检查.Net框架版本 - Check on .Net framework version from WinForms app 如果 .NET Core 应用程序通过 dotnet cli 启动,如何检查运行时 - How to check in runtime if .NET Core app is started via dotnet cli 安装了.Net Core最新的SDK,但未找到'Framework'Microsoft.AspNetCore.App',版本'2.1.0' - .Net Core lastest SDK installed but getting 'Framework 'Microsoft.AspNetCore.App', version '2.1.0' was not found 为什么我的 .NET 框架应用程序会寻找错误版本的 .NET 核心/标准平台扩展程序集,我该如何解决? - Why is my .NET framework app looking for the wrong version of the .NET core/standard platform extension assembly, and how do I fix it? 如何检查可执行文件是否与已安装的.NET版本兼容 - How check if an executable is compatible to the installed .NET version 如何以编程方式检查.Net sdk版本 - how to programmatically check the .Net sdk version 如何确定运行我的应用程序所需的最小.NET框架版本 - How to determine the minimal required .NET framework version to run my app 检查是否安装了完整版的.net? - Check if full version of .net is installed? 通过命令行构建.NET Core应用程序,以便它可以在未安装.NET Core的计算机上运行 - Building a .NET Core app via command line, so that it works on a machine without .NET Core installed 检查是否已安装.NET 4 Full Framework - Check .NET 4 Full Framework is installed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM