当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
C# async 和 await 理解
ACM01 Backpack problem
获取url地址中问号后参数(即使是iframe也可以)
The use of signal function (signal) in C language
es6递归函数
WPF 实现带蒙版的 MessageBox 消息提示框
buck型三相PFC
es6的async函数
PAT1008
Redis的常用数据结构和底层实现方式
Summary of learning stages (knapsack problem)
OC-块对象
wpf path xaml写法和c#写法对比
【Robustness of VQA-1】——2019-EMNLP-Don’t Take the Easy Way Out
redis主从复制
网页控制台控制编辑框
湖南进芯电子替代TIC2000的可能性
log4net使用指南(winform版,sqlserver记录)
C2000在线升级主程序下载kernel完成后跳转到kernel运行的过程记录
_main C:/ti/ccs1011/ccs/tools/compiler/ti-cgt-c2000_20.2.1.LTS/lib/rts2800_fpu32.lib<ar在线升级跳转疑问