How to: Determine Which .NET Framework Versions Are Installed

.NET Framework (current version)
 

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:

Viewing the registry (versions 1-4)
Viewing the registry (version 4.5 and later)
Using code to query the registry (versions 1-4)
Using code 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

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 the installation guide.

To find .NET Framework versions by viewing the registry (.NET Framework 1-4)

  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

    The installed versions are listed under the NDP subkey. The version number is stored in the Version entry. For the .NET Framework 4 the Version entry is under the Client or Full subkey (under NDP), or under both subkeys.

    System_CAPS_ICON_note.jpg Note

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

To find .NET Framework versions by viewing the registry (.NET Framework 4.5 and later)

  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.

    System_CAPS_ICON_note.jpg 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 the .NET Framework 4.5 or newer has been installed on that computer.

    The registry entry for the .NET Framework 4.5.

    The value of the Release DWORD indicates which version of the .NET Framework is installed.

    Value of the Release DWORDVersion
    378389.NET Framework 4.5
    378675.NET Framework 4.5.1 installed with Windows 8.1 or Windows Server 2012 R2
    378758.NET Framework 4.5.1 installed on Windows 8, Windows 7 SP1, or Windows Vista SP2
    379893.NET Framework 4.5.2
    On Windows 10 systems: 393295

    On all other OS versions: 393297
    .NET Framework 4.6
    On Windows 10 November Update systems: 394254

    On all other OS versions: 394271
    .NET Framework 4.6.1
    On Windows 10 Anniversary Update: 394802

    On all other OS versions: 394806
    .NET Framework 4.6.2

To find .NET Framework versions by querying the registry in code (.NET Framework 1-4)

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

    The following code shows an example of this query.

    System_CAPS_ICON_note.jpg Note

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

    Imports Microsoft.Win32
    

        Private Shared Sub GetVersionFromRegistry()
    
            ' Opens the registry key for the .NET Framework entry.
            Using ndpKey As RegistryKey = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, ""). _
                OpenSubKey("SOFTWARE\Microsoft\NET Framework Setup\NDP\")
                ' As an alternative, if you know the computers you will query are running .NET Framework 4.5 
                ' or later, you can use:
    
                ' As an alternative, if you know the computers you will query are running .NET Framework 4.5 
                ' or later, you can use:
                '  Using ndpKey As RegistryKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine,  _
                '  RegistryView.Registry32).OpenSubKey("SOFTWARE\Microsoft\NET Framework Setup\NDP\")
    
                For Each versionKeyName As String In ndpKey.GetSubKeyNames()
                    If versionKeyName.StartsWith("v") Then
                        Dim versionKey As RegistryKey = ndpKey.OpenSubKey(versionKeyName)
                        Dim name As String = DirectCast(versionKey.GetValue("Version", ""), String)
                        Dim sp As String = versionKey.GetValue("SP", "").ToString()
                        Dim install As String = versionKey.GetValue("Install", "").ToString()
                        If install = "" Then
                            'no install info, ust be later
                            Console.WriteLine(versionKeyName & "  " & name)
                        Else
                            If sp <> "" AndAlso install = "1" Then
                                Console.WriteLine(versionKeyName & "  " & name & "  SP" & sp)
    
                            End If
                        End If
                        If name <> "" Then
                            Continue For
                        End If
                        For Each subKeyName As String In versionKey.GetSubKeyNames()
                            Dim subKey As RegistryKey = versionKey.OpenSubKey(subKeyName)
                            name = DirectCast(subKey.GetValue("Version", ""), String)
                            If name <> "" Then
                                sp = subKey.GetValue("SP", "").ToString()
                            End If
                            install = subKey.GetValue("Install", "").ToString()
                            If install = "" Then
                                'no install info, ust be later
                                Console.WriteLine(versionKeyName & "  " & name)
                            Else
                                If 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
    

    The example produces output that's similar to the following:

    
    v2.0.50727  2.0.50727.4016  SP2  
    v3.0  3.0.30729.4037  SP2  
    v3.5  3.5.30729.01  SP1  
    v4  
      Client  4.0.30319  
      Full  4.0.30319  
    
    
    

To find .NET Framework versions by querying the registry in code (.NET Framework 4.5 and later)

  1. The existence of the Release DWORD indicates that the .NET Framework 4.5 or later has been installed on a computer. The value of the keyword indicates the installed version. To check this keyword, use the OpenBaseKey and OpenSubKey methods of the Microsoft.Win32.RegistryKey class to access the Software\Microsoft\NET Framework Setup\NDP\v4\Full subkey under HKEY_LOCAL_MACHINE 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 values listed in the table. Here are the .NET Framework versions and associated Release keywords.

    VersionValue of the Release DWORD
    .NET Framework 4.5378389
    .NET Framework 4.5.1 installed with Windows 8.1378675
    .NET Framework 4.5.1 installed on Windows 8, Windows 7 SP1, or Windows Vista SP2378758
    .NET Framework 4.5.2379893
    .NET Framework 4.6 installed with Windows 10393295
    .NET Framework 4.6 installed on all other Windows OS versions393297
    .NET Framework 4.6.1 installed on Windows 10394254
    .NET Framework 4.6.1 installed on all other Windows OS versions394271
    .NET Framework 4.6.2 installed on Windows 10 Anniversary Update394802
    .NET Framework 4.6.2 installed on all other Windows OS versions394806

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

    Imports Microsoft.Win32
    
    Public Class GetDotNetVersion
       Public Shared 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 Shared Function CheckFor45PlusVersion(releaseKey As Integer) As String
          If releaseKey >= 394802
             Return "4.6.2 or later"
          Else If releaseKey >= 394254 
             Return "4.6.1"
          Else If releaseKey >= 393295
             Return "4.6"
          Else If releaseKey >= 379893
             Return "4.5.2"
          Else If releaseKey >= 378675
             Return "4.5.1"
          Else If releaseKey >= 378389
       	   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 Class   
    ' Calling the GetDotNetVersion.Get45PlusFromRegistry method produces 
    ' 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.

To find the current runtime version by using the Clrver tool

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

    From a Visual Studio Command Prompt, 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).

To find the current runtime version by querying the Environment class in code

  • Query the Environment.Version property to retrieve a Version object that identifies the version of the runtime that is currently executing the code. 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 Object.ToString method to get the entire version string (for example, "4.0.30319.18010", as shown in the following 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.

    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, it has the form 4.0.30319.42000.

    System_CAPS_ICON_important.jpg 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.

    Here's an example of querying the Environment.Version property for runtime version information:

    Imports Microsoft.Win32
    

        Private Shared Sub GetVersionFromEnvironment()
            Console.WriteLine("Version: " & Environment.Version.ToString())
        End Sub
    

    The example produces output that's similar to the following:

    Version: 4.0.30319.18010  
    
    

How to: Determine Which .NET Framework Updates Are Installed
Installation Guide
Versions and Dependencies

Show: