一区二区三区日韩精品-日韩经典一区二区三区-五月激情综合丁香婷婷-欧美精品中文字幕专区

分享

How to: Determine Which .NET Framework Versions Are Installed

 icecity1306 2015-03-16

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.NET Framework 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 theVersion 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 .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 Note

    If the Full subkey is not present, then you do not have a 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 value of the Release DWORD indicates which version of the .NET Framework is installed.

    Value of the Release DWORD

    Version

    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

    381029

    .NET Framework 4.6 Preview

To find .NET Framework versions by querying the registry in code (.NET Framework 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;
    
    
    ...
    
    
    private static void GetVersionFromRegistry()
    {
         // Opens the registry key for the .NET Framework entry. 
            using (RegistryKey ndpKey = 
                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: 
                // 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, must 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, must 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 .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 theMicrosoft.Win32.RegistryKey class to access the Software\Microsoft\NET Framework Setup\NDP\v4.0\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.

    Version

    Value of the Release DWORD

    .NET Framework 4.5

    378389

    .NET Framework 4.5.1 installed with Windows 8.1

    378675

    .NET Framework 4.5.1 installed on Windows 8, Windows 7 SP1, or Windows Vista SP2

    378758

    .NET Framework 4.5.2

    379893

    .NET Framework 4.6 Preview

    381029

    Here's an example of checking for a value greater than or equal to the release keyword values for each version.:

    using System;
    using Microsoft.Win32;
    
    
    ...
    
    
    private static void Get45or451FromRegistry()
    {
    	using (RegistryKey ndpKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey("SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v4\\Full\\")) {
    		int releaseKey = Convert.ToInt32(ndpKey.GetValue("Release"));
    		if (true) {
    			Console.WriteLine("Version: " + CheckFor45DotVersion(releaseKey));
    		}
    	}
    }
    
    
    ...
    
    
    // Checking the version using >= will enable forward compatibility,  
    // however you should always compile your code on newer versions of 
    // the framework to ensure your app works the same. 
    private static string CheckFor45DotVersion(int releaseKey)
    {
    	if ((releaseKey >= 379893)) {
    		return "4.5.2 or later";
    	}
    	if ((releaseKey >= 378675)) {
    		return "4.5.1 or later";
    	}
    	if ((releaseKey >= 378389)) {
    		return "4.5 or later";
    	}
    	// This line 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";
    }
    

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

    Version: 4.5.1 or later
    

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 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, "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.

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

    using System;
    using Microsoft.Win32;
    
    
    ...
    
    
    private static void GetVersionFromEnvironment()
    {
        Console.WriteLine("Version: " + Environment.Version.ToString());
    
    }
    

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

    Version: 4.0.30319.18010
    

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多

    国内午夜精品视频在线观看| 成年人黄片大全在线观看| 日韩欧美亚洲综合在线| 久久中文字幕中文字幕中文| 欧美日韩国产免费看黄片| 91免费一区二区三区| 我的性感妹妹在线观看| 欧美色婷婷综合狠狠爱| 国产精品日韩精品一区| 中文字幕乱码亚洲三区| 国产原创中文av在线播放| 熟女一区二区三区国产| 亚洲一区二区三区一区| 五月综合婷婷在线伊人| 欧美精品在线播放一区二区| 国产精品流白浆无遮挡| 国产成人精品午夜福利| 久久精品亚洲精品国产欧美| 亚洲最新的黄色录像在线| 国产专区亚洲专区久久| 日本特黄特色大片免费观看| 久久这里只有精品中文字幕| 99精品人妻少妇一区二区人人妻| 久久国产精品亚州精品毛片| 黄色片国产一区二区三区| 国产一区二区三区四区中文| 精品丝袜一区二区三区性色| 日韩精品一区二区三区av在线| 狠狠干狠狠操亚洲综合| 丝袜人妻夜夜爽一区二区三区| 精品推荐国产麻豆剧传媒| 中字幕一区二区三区久久蜜桃| 亚洲精品成人综合色在线| 亚洲成人精品免费在线观看| 中文字幕中文字幕在线十八区 | 99日韩在线视频精品免费| 国产精品久久精品毛片| 国产亚洲成av人在线观看| 99精品国产一区二区青青| 国产av乱了乱了一区二区三区| 国产精品一区日韩欧美|