当前位置:网站首页>C# 获取系统已安装的.NET版本
C# 获取系统已安装的.NET版本
2022-07-30 06:05:00 【dotNET跨平台】
本文经原作者授权以原创方式二次分享,欢迎转载、分享。
原文作者:唐宋元明清
原文地址: https://www.cnblogs.com/kybs0/p/16478587.html
C# 获取系统已安装的.NET版本
获取系统已安装的.NET版本,来确定当前应用可运行的环境。

获取系统已安装的.NET版本
微软已经有相应的完整文档,请参考:确定已安装的 .NET Framework 版本 - .NET Framework | Microsoft Docs[1]
Release根据文档描述是版本密钥,应该是类似版本构建号,能够判断是否已安装.NET。
Version是.NetFramework的版本
我整理了下获取Version的方法,方便大家获取:
private Version GetFrameworkVersion()
{
string registerKey = @"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\";
var defaultVersion = new Version(0, 0);
try
{
using (var sub = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey(registerKey))
{
if (!(sub?.GetValue("Release") is int key))
return defaultVersion;
//判断
if (key >= 528040)
return new Version(4, 8);
if (key >= 461808)
return new Version(4, 7, 2);
if (key >= 461308)
return new Version(4, 7, 1);
if (key >= 460798)
return new Version(4, 7);
if (key >= 394802)
return new Version(4, 6, 2);
if (key >= 394254)
return new Version(4, 6, 1);
if (key >= 393295)
return new Version(4, 6);
if (key >= 379893)
return new Version(4, 5, 2);
if (key >= 378675)
return new Version(4, 5, 1);
if (key >= 378389)
return new Version(4, 5);
}
}
catch (Exception)
{
// ignored
}
//小于4.5,一般不存在这个环境
return new Version(0, 0);
}注:如果需要快速获取电脑的.NET版本,可以通过PowerShell查看
(Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Client' -Name Version).Version
参考资料
[1]
确定已安装的 .NET Framework 版本 - .NET Framework | Microsoft Docs: https://docs.microsoft.com/zh-cn/dotnet/framework/migration-guide/how-to-determine-which-versions-are-installed#net_d
边栏推荐
- 云服务器零基础部署网站(保姆级教程)
- 【COCI 2020/2021 Round #2 D】Magneti(DP)
- 进制转换。。。
- 阿里二面:Sentinel vs Hystrix 对比,如何选择?
- The calculation of the determinant of the matrix and its source code
- General Lei's personal blog to see
- How to understand plucker coordinates (geometric understanding)
- MySQL basics [naming convention]
- 从 Google 离职,前Go 语言负责人跳槽小公司
- PXE efficient mass network capacity
猜你喜欢

树状数组的基本用法

golang : Zap log integration

Keil软件中map文件解析

When does MySQL use table locks and when does it use row locks?

这个终端连接工具,碾压Xshell

export , export default, import complete usage

What happens when @Bean and @Component are used on the same class?

Calculate the inverse source of the matrix (using the adjoint matrix, a 3x3 matrix)

Go combines Gin to export Mysql data to Excel table

uniapp中canvas与v-if更“配”
随机推荐
idea built-in translation plugin
The introduction of AI meta-learning into neuroscience, the medical effect is expected to improve accurately
让百度地图生成器里的“标注”内容展开--解决方案
Go: use gorm query record
VR机器人教你如何正确打乒乓球
Redis 如何实现防止超卖和库存扣减操作?
How to use Swagger, say goodbye to postman
redis实现分布式锁的原理
MySQL基础篇【命名规范】
Ali: How many methods are there for multi-threaded sequential operation?
手机端滚动至页面指定位置
mysql高阶语句(一)
深度学习:线性回归模型
Proof of distance calculation from space vertex to plane and its source code
【雷达目标检测】恒定阈值法和恒虚警(CFAR)法及代码实现
DP5340 domestic replacement for CM5340 stereo audio A/D converter chip
Oracle查看表空间使用率及爆满解决方案
go : 使用gorm查询记录
The terminal connection tools, rolling Xshell
头条二面:MySQL中有几种常见的 SQL 错误用法?