[英]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:为了省去您必须在注册表中查询这些位置的麻烦:
HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\dotnet\Setup\InstalledVersions\x64\sharedfx\Microsoft.NETCore.App
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.这可能会在未来发生变化,但从我所看到的和我的机器来看,所有版本都记录在这些位置。
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.