.NET - 我当前正在运行哪个版本的框架(来自C#)

11
使用 C#,询问 .NET Runtime 正在运行的版本的最佳方法是什么?答案:使用 Environment.Version 属性。
3个回答

18

这个较新的属性更适用于 .NET Framework 4.5 之后的 System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription。 - Simon_Weaver

6
重要的是要小心询问正在运行的框架版本以及正在运行的运行时版本,因为它们可能不同。您的标题和正文提出了微妙不同的问题。
@JaredPar在运行时版本方面是正确的。
对于框架版本,请查看这篇密切相关的帖子:如何检测安装了哪些.NET Framework版本和服务包?

最新安装的版本可能与当前程序集运行的版本不同。获取当前执行的框架版本应该比检查已安装的版本更容易。(但在这方面缺乏答案表明情况并非如此) - NiKiZe

2
  • You can write a simple method for this purpose:

    public static void GetVersion() {   
     Environment.Version.ToString() }
    
输出是你的 .NET 版本。
  • You can also find the installed versions in the following location:

    C:\WINDOWS\Microsoft.NET\Framework
    
  • If you are using Visual Studio, run Visual Studio commander from the start menu, and enter clrver , and it gives you the running version.

  • And for sure, you can always check your registry for that:

    HKEY_LOCAL_MACHINE \ software \ Microsoft \ Net Framework \
    

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接