当前位置:网站首页>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

边栏推荐
- _main C:/ti/ccs1011/ccs/tools/compiler/ti-cgt-c2000_20.2.1.LTS/lib/rts2800_fpu32.lib<ar在线升级跳转疑问
- 索引index
- 推荐一个免费50时长的AI算力平台
- Double pointer - the role of char **, int **
- [C language] creation and use of dynamic arrays
- web course design
- CANopen DS402名词
- TIC2000系列处理器在线升级
- 从零开始Blazor Server(9)--修改Layout
- 专业人士使用的 11 种渗透测试工具
猜你喜欢
随机推荐
百钱买鸡(一)
信号量SIGCHLD的使用,如何让父进程得知子进程执行结束,如何让父进程区分多个子进程的结束
es6递归函数
BISS绝对值编码器_TI方案_线路延迟补偿
gdb tui的使用
ACM01 Backpack problem
Redis的常用数据结构和底层实现方式
The use of C language typedef 】 : structure, basic data types, and array
【Robustness of VQA-1】——2019-EMNLP-Don’t Take the Easy Way Out
PAT1008
在北京参加UI设计培训到底怎么样?
PAT1003
WPF 实现带蒙版的 MessageBox 消息提示框
proto3-2 syntax
How tall is the B+ tree of the MySQL index?
wait system call
Modify the VOT2018.json file and remove the color in the image path
es6Generator函数的异常处理
【VQA survey】视觉问答中的语言学问题
ICML 2022 | Out-of-Distribution Detection with Deep Nearest Neighbors