首页 > Windows开发 > 详细

c# .NET Framework 版本确定

时间:2019-12-07 22:54:28      阅读:125      评论:0      收藏:0      [点我收藏+]

关于.NET Framework 版本信息这里做个介绍:

1. 编译时,工程的目标的 .NET Framework 版本

技术分享图片

 

同样的代码,我先选择.net 4.0,就发现有语法错误,原因是4.0版本还没提供这个API

技术分享图片

改选 .net 4.5,语法错误消失了,因为这个API在后续的 .net已经添加了

 技术分享图片

 但是运行起来,真正使用的 .NET Framework版本就不一定是目标版本了。

 

2. 运行时实际的Framework版本

真实运行的Framework版本跟机器安装的 Framework 版本有关,如果目标是4.5,机器上只装了 4.8。

那么由于向下兼容的原则,运行时CLR就会使用4.8去运行程序。如果机器只安装了3.5,那么CLR就会弹出一个提示框让用户去安装 4.5。

 

如何确定机器安装的 Framework版本呢?一般都是查看注册表:

输入 regedit 打开注册表,并找到这一项:

 

计算机\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP

 

.NET Framework 4.5之前的版本可以这样依次确认:

技术分享图片

技术分享图片

 

4.5以及之后的版本需要这样确认:

技术分享图片

Release的值对应了 .NET Framework版本,下面是微软列举每个版本的值

 .NET Framework version  Value of the Release DWORD
.NET Framework 4.5 All Windows operating systems: 378389
.NET Framework 4.5.1 On Windows 8.1 and Windows Server 2012 R2: 378675
On all other Windows operating systems: 378758
.NET Framework 4.5.2 All Windows operating systems: 379893
.NET Framework 4.6 On Windows 10: 393295
On all other Windows operating systems: 393297
.NET Framework 4.6.1 On Windows 10 November Update systems: 394254
On all other Windows operating systems (including Windows 10): 394271
.NET Framework 4.6.2 On Windows 10 Anniversary Update and Windows Server 2016: 394802
On all other Windows operating systems (including other Windows 10 operating systems): 394806
.NET Framework 4.7 On Windows 10 Creators Update: 460798
On all other Windows operating systems (including other Windows 10 operating systems): 460805
.NET Framework 4.7.1 On Windows 10 Fall Creators Update and Windows Server, version 1709: 461308
On all other Windows operating systems (including other Windows 10 operating systems): 461310
.NET Framework 4.7.2 On Windows 10 April 2018 Update and Windows Server, version 1803: 461808
On all Windows operating systems other than Windows 10 April 2018 Update and Windows Server, version 1803: 461814
.NET Framework 4.8 On Windows 10 May 2019 Update and Windows 10 November 2019 Update: 528040
On all other Windows operating systems (including other Windows 10 operating systems): 528049

 

 

 

 

 

 

 

 

 

 

 

 

 

3. 关于CLR版本

除了.NET Framework的assembly,还有CLR(公共语言运行时),它负责管理执行code,它的版本需要这样确认:

输入命令:clrver

技术分享图片

 

CLR 2.0可以管理 .NET Framework 2.0 3.0 3.5

CLR 4.0可以管理 .NET Framework 4.0 4.5 4.5以上版本

 

4. 其他

.net 3.5 需要开启windows功能才能正常使用,如下图:

技术分享图片

 

用code 辨识版本号

// 工程配置的目标Framework版本
Console.WriteLine(AppDomain.CurrentDomain.SetupInformation.TargetFrameworkName);
// 实际真实运行的Framework版本
Console.WriteLine(FileVersionInfo.GetVersionInfo(typeof(Uri).Assembly.Location).ProductVersion);

 

 结果

技术分享图片

 

.NET 4.0 和 .NET 4.0 Client Profile 版本的区别:

4 Client Profile 是.4的子集,更轻量,更小

 

c# .NET Framework 版本确定

原文:https://www.cnblogs.com/chenyingzuo/p/12003513.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!