【问题标题】:How to get the .NET framework version that the application is using [duplicate]如何获取应用程序正在使用的 .NET 框架版本 [重复]
【发布时间】:2013-02-28 05:53:30
【问题描述】:

我提到了堆栈溢出问题Is there an easy way to check the .NET Framework version?。但是那里给出的建议对以下目的不起作用。

我们如何识别 C# 控制台应用程序正在使用的 .NET 版本?

环境:

  • Visual Studio 2010
  • .NET Framework:3.5(请看附件截图)

代码

using System;
using System.Globalization;
using Microsoft.Win32;
namespace TESTConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            //.NET version: Approach 1
            RegistryKey installed_versions = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\NET Framework Setup\NDP");
            string[] version_names = installed_versions.GetSubKeyNames();
            double latestFramework = Convert.ToDouble(version_names[version_names.Length - 1].Remove(0, 1), CultureInfo.InvariantCulture);
            int SP = Convert.ToInt32(installed_versions.OpenSubKey(version_names[version_names.Length - 1]).GetValue("SP", 0));
            Console.WriteLine(latestFramework);

            //Approach 2
            string versionval = Environment.Version.ToString();
            Console.WriteLine(versionval);

            //Approach 3
            string systemVersionVal = System.Runtime.InteropServices.RuntimeEnvironment.GetSystemVersion().ToString();
            Console.WriteLine(systemVersionVal);

            Console.ReadLine();
        }
    }
}

输出

版本设置

【问题讨论】:

  • @Habib 抱歉
  • 这对stackoverflow.com/a/8543850/284111有帮助吗?
  • 您需要更具体地说明您需要什么“版本” - 为 3.5 构建您将获得运行时 2.0 或 4.0。这可能是您需要的,但澄清会有所帮助。

标签: c#


【解决方案1】:

接近的第二个和第三个是CLR version numbers

.NET Framework 2 和 .NET Framework 3.5 正在使用 CLR 2.0

而且没有 CLR 3.0 或 3.5。

【讨论】:

  • 这...除非您正在加载 WCF 库,否则我不确定它会说什么...
猜你喜欢
  • 1970-01-01
  • 2018-12-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-17
相关资源
最近更新 更多