我已经提到堆栈溢出问题Is there an easy way to check the .NET Framework version?。但是那里给出的建议没有用于以下目的。如何获得应用程序正在使用的.NET框架版本
我们如何识别C#控制台应用程序正在使用的.NET版本?
环境:
- Visual Studio 2010中
- 的.NET Framework 3.5(请参阅附截图)
CODE
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();
}
}
}
输出
VERSION设置
@Habib对不起,那个 – 1Mayur 2013-02-28 06:00:51
这有助于http://stackoverflow.com/a/8543850/284111? – 2013-02-28 06:03:01
你需要更具体的什么“版本”你需要 - 与建设3.5你得到运行时2.0或4.0。这可能是你需要的,但澄清会有帮助。 – 2013-02-28 06:21:04