21 out of 40 rated this helpful - Rate this topic

How to: Determine Which .NET Framework Versions Are Installed

.NET Framework 4.5

The .NET Framework consists of two main components: a set of assemblies, which are collections of types and resources that provide the functionality for your apps, and the common language runtime (CLR), which manages and executes your app's code. These two components are versioned separately. The .NET Framework and assemblies share the same version number, and the CLR is identified by its own version number (see .NET Framework Versions and Dependencies). You can install and run multiple versions of the .NET Framework on your computer. To see which versions of the .NET Framework are installed on your computer, you should view the entries in the Windows registry. To determine which version of the CLR is currently executing code, you can use the System.Environment class.

This article provides instructions for detecting .NET Framework versions on a computer both manually and programmatically, and detecting the runtime version programmatically. 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 the installed .NET Framework versions manually (versions 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.

    Note Note

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

To find the installed .NET Framework versions manually (versions 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

    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.

    Version

    Value of the Release DWORD

    .NET Framework 4.5

    378389

    .NET Framework 4.5.1 Preview

    378575

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

  • Use the Microsoft.Win32.RegistryKey class 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.

    Note 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.

    using System;
    using Microsoft.Win32;
    
    public class GetDotNetVersion
    {
        public static void Main()
        {
            using (RegistryKey ndpKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey(@"SOFTWARE\Microsoft\NET Framework Setup\NDP\"))
            {
                foreach (string versionKeyName in ndpKey.GetSubKeyNames())
                {
                    if (versionKeyName.StartsWith("v"))
                    {
    
                        RegistryKey versionKey = ndpKey.OpenSubKey(versionKeyName);
                        string name = (string)versionKey.GetValue("Version", "");
                        string sp = versionKey.GetValue("SP", "").ToString();
                        string install = versionKey.GetValue("Install", "").ToString();
                        if (install == "") //no install info, ust be later
                            Console.WriteLine(versionKeyName + "  " + name);
                        else
                        {
                            if (sp != "" && install == "1")
                            {
                                Console.WriteLine(versionKeyName + "  " + name + "  SP" + sp);
                            }
    
                        }
                        if (name != "")
                        {
                            continue;
                        }
                        foreach (string subKeyName in versionKey.GetSubKeyNames())
                        {
                            RegistryKey subKey = versionKey.OpenSubKey(subKeyName);
                            name = (string)subKey.GetValue("Version", "");
                            if (name != "")
                                sp = subKey.GetValue("SP", "").ToString();
                            install = subKey.GetValue("Install", "").ToString();
                            if (install == "") //no install info, ust be later
                                Console.WriteLine(versionKeyName + "  " + name);
                            else
                            {
                                if (sp != "" && install == "1")
                                {
                                    Console.WriteLine("  " + subKeyName + "  " + name + "  SP" + sp);
                                }
                                else if (install == "1")
                                {
                                    Console.WriteLine("  " + subKeyName + "  " + name);
                                }
    
                            }
    
                        }
    
                    }
                }
            }
        }
    }
    

    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 the current runtime version by querying the Environment class in code

  • Query the Version property of the Environment class to identify 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, "3" for version 3.5), the Version.Minor property to get the minor release identifier (for example, "5" for version 3.5), 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.

    The following code shows an example of querying the Environment.Version property for runtime version information.

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

    Version: 4.0.30319.18010
    
Did you find this helpful?
(1500 characters remaining)
© 2013 Microsoft. All rights reserved.