I have referred to the Stack Overflow question Is there an easy way to check the .NET Framework version?. But the suggestions given there did not work for the following purpose.
How can we identify the .NET version that the C# console application is using?
Environment:
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();
}
}
}
Output
VERSION Setup
The 2nd and 3rd approached are the CLR version numbers
.
.NET Framework 2 and .NET Framework 3.5 are using CLR 2.0
.
And there's no CLR 3.0 or 3.5.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With