How can I check from a c# application itself, what version of dotnet being used by application?
Asked
Active
Viewed 6,471 times
7
-
Did you mean the minimal version required by the application? (TargetFrameworkVersion attr in project file) – Ralf de Kleine Feb 23 '11 at 10:49
-
Actually I need path of current application framework. My application needs to execute some exe from current running version. i.e., if my application is using 2.0 it will pick exe from .net 2.0 folder and if using 4 it will pick exe from .net 4.0 folder. – hungryMind Feb 23 '11 at 12:17
4 Answers
14
Use Environment.Version
- it gives you the exact version of .NET running the application.
Gets a Version object that describes the major, minor, build, and revision numbers of the common language runtime.
To find out what version of the framework is installed, see this SO question and answers. In a nut shell, you will need to dig into the registry.
-
3Can it distinguish between 3.5, 3.0 and 2.0? (the runtime is the same, 2.0.something) – xanatos Feb 23 '11 at 10:52
-
@xanatos - No, it can't. It will return the runtime version. If you need to know what is installed, see [this](http://stackoverflow.com/questions/199080/how-to-detect-what-net-framework-versions-and-service-packs-are-installed) SO question and answers. – Oded Feb 23 '11 at 11:14
7
You can use the:
Environment.Version
to get the version number of the .NET runtime.

Anders Zommarin
- 7,094
- 2
- 25
- 24
0
Create a Console app add this class and run it
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication2
{
public class GetDotNetVersion
{
public static void Get45PlusFromRegistry()
{
const string subkey = @"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\";
using (RegistryKey ndpKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey(subkey))
{
if (ndpKey != null && ndpKey.GetValue("Release") != null)
{
Console.WriteLine(".NET Framework Version: " + CheckFor45PlusVersion((int)ndpKey.GetValue("Release")));
}
else
{
Console.WriteLine(".NET Framework Version 4.5 or later is not detected.");
}
}
}
// Checking the version using >= will enable forward compatibility.
private static string CheckFor45PlusVersion(int releaseKey)
{
if (releaseKey >= 394802)
return "4.6.2 or later";
if (releaseKey >= 394254)
{
return "4.6.1";
}
if (releaseKey >= 393295)
{
return "4.6";
}
if ((releaseKey >= 379893))
{
return "4.5.2";
}
if ((releaseKey >= 378675))
{
return "4.5.1";
}
if ((releaseKey >= 378389))
{
return "4.5";
}
// This code should never execute.
// that 4.5 or later is installed.
return "No 4.5 or later version detected";
}
}
// Calling the GetDotNetVersion.Get45PlusFromRegistry method produces
// output like the following:
// .NET Framework Version: 4.6.1
}

Metallic Skeleton
- 607
- 6
- 27
-
Add some explanation with answer for how this answer help OP in fixing current issue – ρяσѕρєя K Oct 07 '16 at 08:58
0
In your Visual Studio, go to Tools->Nutget Package Management->Package Manager Console Type in dotnet --version And here you go!

AntiqueWhale
- 171
- 1
- 4