c# .NET Framework 版本确定
关于.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的子集,更轻量,更小
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
· 【杂谈】分布式事务——高大上的无用知识?