How to: Determine which .NET Framework versions are installed

Users can install and run multiple versions of the .NET Framework on their computers. When you develop or deploy your app, you might need to know which .NET Framework versions are installed on the user’s computer. Note that the .NET Framework consists of two main components, which are versioned separately:

  • A set of assemblies, which are collections of types and resources that provide the functionality for your apps. The .NET Framework and assemblies share the same version number.

  • The common language runtime (CLR), which manages and executes your app's code. The CLR is identified by its own version number (see Versions and Dependencies).

To get an accurate list of the .NET Framework versions installed on a computer, you can view the registry or query the registry in code:

Find .NET Framework versions 1-4 in the registry
Find .NET Framework versions 4.5 and later in the registry)
Using code to query the registry (versions 1-4)
Using code to query the registry (version 4.5 and later)
Using PowerShell to query the registry (version 4.5 and later)

To find the CLR version, you can use a tool or code:

Using the Clrver tool
Using code to query the System.Environment class

Note

There is a difference between the .NET Framework version and the common language runtime (CLR) version. The .NET Framework is versioned based on the set of assemblies that form the .NET Framework Class Library. For example, .NET Framework versions include 4.5, 4.6.1, and 4.7.2. The CLR is versioned based on the runtime on which .NET Framework applications execute, and a single CLR version typically supports multiple .NET Framework versions. CLR version 4.30319.xxxxx supports .NET Framework versions 4 through 4.5.2; CLR version 4.30319.42000 supports .NET Framework versions starting with .NET Framework 4.6. For more information, see the Environment.Version property.

For information about detecting the installed updates for each version of the .NET Framework, see How to: Determine Which .NET Framework Updates Are Installed. For information about installing the .NET Framework, see Install the .NET Framework for developers.

Find .NET Framework versions 1-4 in the registry

  1. On the Start menu, choose Run.

  2. In the Open box, enter regedit.exe.

    You must have administrative credentials to run regedit.exe.

  3. In the Registry Editor, open the following subkey:

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP

    For .NET Framework versions 1.1 through 3.5, the installed versions are listed as subkeys under the NDP subkey. The version number is stored in the version subkey's Version entry.

    For .NET Framework 4, the Version entry is under the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4.0\Client subkey, the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4.0\Full subkey, or under both subkeys.

    Note

    The "NET Framework Setup" folder in the registry does not begin with a period.

    The following figure shows that the subkey for the .NET Framework 3.5 along with its Version entry.

    The registry entry for the .NET Framework 3.5.

Find .NET Framework versions 4.5 and later in the registry

  1. On the Start menu, choose Run.

  2. In the Open box, enter regedit.exe.

    You must have administrative credentials to run regedit.exe.

  3. In the Registry Editor, open the following subkey:

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full

    Note that the path to the Full subkey includes the subkey Net Framework rather than .NET Framework.

    Note

    If the Full subkey is not present, then you do not have the .NET Framework 4.5 or later installed.

    Check for a DWORD value named Release. The existence of the Release DWORD indicates that .NET Framework 4.5 or later has been installed on that computer. Its value is a release key that corresponds to a particular version of .NET Framework. In the following figure, for example, the value of the Release DWORD is 378389, which is the release key for .NET Framework 4.5.

    The registry entry for the .NET Framework 4.5.

The following table lists the minimum value of the Release DWORD for each .NET Framework version. You can use these values as follows:

  • To determine whether a minimum .NET Framework version is present, test whether the Release DWORD value found in the registry is greater than or equal to the value listed in the table. For example, if your application requires .NET Framework 4.7 or later, you would test for a minimum release key value of 460798.

  • To test for multiple versions, begin with the latest .NET Framework version, and then test for each successive earlier version.

Important

The following table lists the keys of released versions of the .NET Framework only. It doesn't list the keys of preview or pre-release versions.

.NET Framework Version Value of the Release DWORD
.NET Framework 4.5 378389
.NET Framework 4.5.1 378675
.NET Framework 4.5.2 379893
.NET Framework 4.6 393295
.NET Framework 4.6.1 394254
.NET Framework 4.6.2 394802
.NET Framework 4.7 460798
.NET Framework 4.7.1 461308
.NET Framework 4.7.2 461808

For a complete table of release keys for the .NET Framework for specific Windows operating system versions, see .NET Framework release keys and Windows operating system versions.

Find .NET Framework versions 1-4 with code

  • Use the Microsoft.Win32.RegistryKey class to access the Software\Microsoft\NET Framework Setup\NDP\ subkey under HKEY_LOCAL_MACHINE branch in the Windows registry.

    The following code shows an example of this query.

    Note

    This code does not show how to detect .NET Framework 4.5 or later. Check the Release DWORD to detect those versions, as described in the previous section. For code that detects .NET Framework 4.5 or later versions, see the next section in this article.

    using Microsoft.Win32;
    using System;
    
    public static class VersionTest
    {
        public static void Main()
        {
            GetVersionFromRegistry();
        }
        
        private static void GetVersionFromRegistry()
        {
            // Opens the registry key for the .NET Framework entry.
            using (RegistryKey ndpKey = 
                    RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).
                    OpenSubKey(@"SOFTWARE\Microsoft\NET Framework Setup\NDP\"))
            {
                foreach (var versionKeyName in ndpKey.GetSubKeyNames())
                {
                    // Skip .NET Framework 4.5 version information.
                    if (versionKeyName == "v4")
                    {
                        continue;
                    }
    
                    if (versionKeyName.StartsWith("v"))
                    {
    
                        RegistryKey versionKey = ndpKey.OpenSubKey(versionKeyName);
                        // Get the .NET Framework version value.
                        var name = (string)versionKey.GetValue("Version", "");
                        // Get the service pack (SP) number.
                        var sp = versionKey.GetValue("SP", "").ToString();
    
                        // Get the installation flag, or an empty string if there is none.
                        var install = versionKey.GetValue("Install", "").ToString();
                        if (string.IsNullOrEmpty(install)) // No install info; it must be in a child subkey.
                            Console.WriteLine($"{versionKeyName}  {name}");
                        else
                        {
                            if (!(string.IsNullOrEmpty(sp)) && install == "1")
                            {
                                Console.WriteLine($"{versionKeyName}  {name}  SP{sp}");
                            }
                        }
                        if (! string.IsNullOrEmpty(name))
                        {
                            continue;
                        }
                        foreach (var subKeyName in versionKey.GetSubKeyNames())
                        {
                            RegistryKey subKey = versionKey.OpenSubKey(subKeyName);
                            name = (string)subKey.GetValue("Version", "");
                            if (! string.IsNullOrEmpty(name))
                                sp = subKey.GetValue("SP", "").ToString();
                            
                            install = subKey.GetValue("Install", "").ToString();
                            if (string.IsNullOrEmpty(install)) //No install info; it must be later.
                                Console.WriteLine($"{versionKeyName}  {name}");
                            else
                            {
                                if (!(string.IsNullOrEmpty(sp )) && install == "1")
                                {
                                    Console.WriteLine($"{subKeyName}  {name}  SP{sp}");
                                }
                                else if (install == "1")
                                {
                                    Console.WriteLine($"  {subKeyName}  {name}");
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    // The example displays output similar to the following:
    //        v2.0.50727  2.0.50727.4927  SP2
    //        v3.0  3.0.30729.4926  SP2
    //        v3.5  3.5.30729.4926  SP1
    //        v4.0
    //        Client  4.0.0.0
    
    Imports Microsoft.Win32
    
    Public Module VersionTest
        Public Sub Main()
            GetVersionFromRegistry()
        End Sub
        
        Private Sub GetVersionFromRegistry()
    
            ' Opens the registry key for the .NET Framework entry.
            Using ndpKey As RegistryKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32). 
                OpenSubKey("SOFTWARE\Microsoft\NET Framework Setup\NDP\")
    
                For Each versionKeyName In ndpKey.GetSubKeyNames()
                    ' Skip .NET Framework 4.5 and later.
                    If versionKeyName = "v4" Then Continue For
    
                    If versionKeyName.StartsWith("v") Then
                        Dim versionKey As RegistryKey = ndpKey.OpenSubKey(versionKeyName)
                        ' Get the .NET Framework version value.
                        Dim name = DirectCast(versionKey.GetValue("Version", ""), String)
                        ' Get the service pack (SP) number.
                        Dim sp = versionKey.GetValue("SP", "").ToString()
                       
                        Dim install = versionKey.GetValue("Install", "").ToString()
                        If String.IsNullOrEmpty(install) Then  ' No install info; it must be in a child subkey.
                            Console.WriteLine($"{versionKeyName}  {name}")
                        Else
                            If Not String.IsNullOrEmpty(sp) AndAlso install = "1" Then
                                Console.WriteLine($"{versionKeyName}  {name}  SP{sp}")
                            End If
                        End If
                        If Not String.IsNullOrEmpty(name) Then
                            Continue For
                        End If
                        For Each subKeyName In versionKey.GetSubKeyNames()
                            Dim subKey As RegistryKey = versionKey.OpenSubKey(subKeyName)
                            name = DirectCast(subKey.GetValue("Version", ""), String)
                            If Not String.IsNullOrEmpty(name) Then
                                sp = subKey.GetValue("SP", "").ToString()
                            End If
                            install = subKey.GetValue("Install", "").ToString()
                            If String.IsNullOrEmpty(install) Then  ' No install info; it must be later.
                                Console.WriteLine($"{versionKeyName}  {name}")
                            Else
                                If Not String.IsNullOrEmpty(sp) AndAlso install = "1" Then
                                    Console.WriteLine($"{subKeyName}  {name}  SP{sp}")
                                ElseIf install = "1" Then
                                    Console.WriteLine($"  {subKeyName}  {name}")
                                End If
                            End If
                        Next
                    End If
                Next
            End Using
        End Sub
    End Module
    ' The example displays output similar to the following:
    '        v2.0.50727  2.0.50727.4927  SP2
    '        v3.0  3.0.30729.4926  SP2
    '        v3.5  3.5.30729.4926  SP1
    '        v4.0
    '        Client  4.0.0.0
    

Find .NET Framework versions 4.5 and later with code

  1. The existence of the Release DWORD in the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full key indicates that the .NET Framework 4.5 or later is installed on a computer. The value of the keyword indicates the installed version. To check this keyword, use the RegistryKey.OpenBaseKey and RegistryKey.OpenSubKey methods to access the subkey in the Windows registry.

  2. Check the value of the Release keyword to determine the installed version. To be forward-compatible, you can check for a value greater than or equal to the value listed in the table in the Find .NET Framework versions 4.5 and later in the registry section.

The following example checks the Release value in the registry to determine whether .NET Framework 4.5 or a later version is installed.

using System;
using Microsoft.Win32;

public class GetDotNetVersion
{
   public static void Main()
   {
      GetDotNetVersion.Get45PlusFromRegistry();
   }

   private static void Get45PlusFromRegistry()
   {
      const string subkey = @"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\";

      using (var 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 >= enables forward compatibility.
      string CheckFor45PlusVersion(int releaseKey)
      {
         if (releaseKey >= 461808)
            return "4.7.2 or later";
         if (releaseKey >= 461308)
            return "4.7.1";
         if (releaseKey >= 460798)
            return "4.7";
         if (releaseKey >= 394802)
            return "4.6.2";
         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. A non-null release key should mean
         // that 4.5 or later is installed.
         return "No 4.5 or later version detected";
      }
   }
}   
// This example displays output like the following:
//       .NET Framework Version: 4.6.1
Imports Microsoft.Win32

Public Module GetDotNetVersion
   Public Sub Main()
      Get45PlusFromRegistry()
   End Sub

   Private Sub Get45PlusFromRegistry()
      Const subkey As String = "SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\"

      Using ndpKey As RegistryKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey(subkey)
         If ndpKey IsNot Nothing AndAlso ndpKey.GetValue("Release") IsNot Nothing 
            Console.WriteLine(".NET Framework Version: " + CheckFor45PlusVersion(ndpKey.GetValue("Release")))
         Else 
            Console.WriteLine(".NET Framework Version 4.5 or later is not detected.")
         End If 
      End Using
   End Sub

   ' Checking the version using >= will enable forward compatibility.
   Private Function CheckFor45PlusVersion(releaseKey As Integer) As String
      If releaseKey >= 461308 Then
         Return "4.7.1 or later"
      Else If releaseKey >= 460798 Then
         Return "4.7"
      Else If releaseKey >= 394802 Then
         Return "4.6.2"
      Else If releaseKey >= 394254 Then 
         Return "4.6.1"
      Else If releaseKey >= 393295 Then
         Return "4.6"
      Else If releaseKey >= 379893 Then
         Return "4.5.2"
      Else If releaseKey >= 378675 Then
         Return "4.5.1"
      Else If releaseKey >= 378389 Then
         Return "4.5"
      End If
      ' This code should never execute. A non-null release key should mean
      ' that 4.5 or later is installed.
        Return "No 4.5 or later version detected"
   End Function
End Module   
' The example displays output like the following:
'       .NET Framework Version: 4.6.1

This example follows the recommended practice for version checking:

  • It checks whether the value of the Release entry is greater than or equal to the value of the known release keys.

  • It checks in order from most recent version to earliest version.

Check for a minimum required .NET Framework version (4.5 and later) with PowerShell

The following example checks the value of the Release keyword to determine whether .NET Framework 4.6.2 or higher is installed (returning True if it is and False otherwise).

```PowerShell
# PowerShell 5
Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\' | Get-ItemPropertyValue -Name Release | Foreach-Object { $_ -ge 394802 } 
```

```PowerShell
# PowerShell 4
(Get-ItemProperty "HKLM:SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full").Release -gt 394802
```

You can replace `394802` in the previous example with another value from the following table in the [Find .NET Framework versions 4.5 and later in the registry](#net_b) section to check for a different minimum required .NET Framework version.

Find the current CLR version with Clrver.exe

Use the CLR Version Tool (Clrver.exe) to determine which versions of the common language runtime are installed on a computer.

From a Developer Command Prompt for Visual Studio, enter clrver. This command produces output similar to the following:

Versions installed on the machine:
v2.0.50727
v4.0.30319

For more information about using this tool, see Clrver.exe (CLR Version Tool).

Find the current CLR version with the Environment class

You can retrieve the value of the Environment.Version property to retrieve a Version object that identifies the version of the runtime that is currently executing the code. This property returns a single value that reflects the version of the runtime that is currently executing the code; it does not return assembly versions or other versions of the runtime that may have been installed on the computer.You can use the Version.Major property to get the major release identifier (for example, "4" for version 4.0), the Version.Minor property to get the minor release identifier (for example, "0" for version 4.0), or the Version.ToString method to get the entire version string (for example, "4.0.30319.18010", as shown in the following code).

For the .NET Framework Versions 4, 4.5, 4.5.1, and 4.5.2, the Environment.Version property returns a Version object whose string representation has the form 4.0.30319.xxxxx. For the .NET Framework 4.6 and later, it has the form 4.0.30319.42000.

Important

For the .NET Framework 4.5 and later, we do not recommend using the Environment.Version property to detect the version of the runtime. Instead, we recommend that you query the registry, as described in the To find .NET Framework versions by querying the registry in code (.NET Framework 4.5 and later) section earlier in this article.

The following example used the Environment.Version property to retrieve runtime version information:

using System;

public class VersionTest
{
    public static void Main()
    {
        Console.WriteLine($"Version: {Environment.Version}");
    }
}
// The example displays output similar to the following:'
//    Version: 4.0.30319.18010
Imports Microsoft.Win32

Public Module VersionTest
   Public Sub Main()
      GetVersionFromEnvironment()
   End Sub
   
    Private Sub GetVersionFromEnvironment()
        Console.WriteLine($"Version: {Environment.Version}")
    End Sub
End Module
' The example displays output similiar to the following:'
'    Version: 4.0.30319.18010

See also