当前位置:网站首页>C# Get system installed .NET version
C# Get system installed .NET version
2022-08-09 11:45:00 【yanjinhua】
本文经原作者授权以原创方式二次分享,欢迎转载、分享.
原文作者:唐宋元明清
原文地址: https://www.cnblogs.com/kybs0/p/16478587.html
C# Get system installed.NET版本
Get system installed.NET版本,to determine the environment in which the current application can run.

Get system installed.NET版本
Microsoft already has the corresponding full documentation,请参考:确定已安装的 .NET Framework 版本 - .NET Framework | Microsoft Docs
ReleaseAccording to the documentation it is the version key,Should be a similar version build number,Can determine whether it is installed.NET.
Version是.NetFramework的版本
I sorted it outVersion的方法,方便大家获取:
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,This environment generally does not exist
return new Version(0, 0);
}
注:Get a computer quickly if you need it. NET版本,可以通过 PowerShell查看
(Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Client' -Name Version).Version

边栏推荐
猜你喜欢
随机推荐
百钱买鸡(一)
Win10调整磁盘存储空间详解
Chinese valentine's day?Programmers don't exist
[现代控制理论]5_系统的可控性_controllability
【精华文】C语言结构体特殊情况分析:结构体指针 / 基本数据类型指针,指向其他结构体
[现代控制理论]4_PhasePortrait爱情故事动态系统分析
This application has no explicit mapping for /error, so you are seeing this as a fallback
未来装备探索:数字孪生装备
win10右键文件,一直转圈
es6的async函数
bat文件(批处理文件)运行时一闪而过解决方法
【C language】动态数组的创建和使用
wait system call
ThreadLocal类
Visual Studio 2017 ASP.NET Framework MVC 项目 MySQL 配置连接
MySQL的MVVC多版本并发控制机制
排序--快排(图解)
网页控制台控制编辑框
LeetCode 1413.逐步求和得到正数的最小值
Redis高可用部署









