我如何找到 .NET 版本?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1565434/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 13:26:59  来源:igfitidea点击:

How do I find the .NET version?

.net

提问by sepang

How do I find out which version of .NET is installed?

如何找出安装的 .NET 版本?

I'm looking for something as simple as "java -version" that I can type at the command prompt and that tells me the current version(s) installed.

我正在寻找像“java -version”这样简单的东西,我可以在命令提示符下输入它并告诉我安装的当前版本。

I better add that Visual Studio may not be installed - this is typically something that I want to know about a client machine.

我最好补充一点,可能未安装 Visual Studio - 这通常是我想了解的有关客户端计算机的信息。

采纳答案by Binoj Antony

Just type any oneof the below commands to give you the latest version in the first line.

只需键入以下任何一个命令,即可在第一行为您提供最新版本。

1. CSC
2. GACUTIL /l ?
3. CLRVER

You can only run these from the Visual Studio Command prompt if you have Visual Studio installed, or else if you have the .NET framework SDK, then the SDK Command prompt.

如果安装了 Visual Studio,则只能从 Visual Studio 命令提示符运行这些程序,否则,如果安装了 .NET 框架 SDK,则可以从 SDK 命令提示符运行。

4. wmic product get description | findstr /C:".NET Framework"
5. dir /b /ad /o-n %systemroot%\Microsoft.NET\Framework\v?.*

The last command (5) will list out all the versions(except 4.5) of .NET installed, latest first.
You need to run the 4th command to see if .NET 4.5 is installed.

最后一个命令 (5) 将列出已安装的所有.NET版本(4.5 除外),最新在前
您需要运行第四条命令来查看是否安装了 .NET 4.5。

Another three options from the PowerShell command prompt is given below.

下面给出了 PowerShell 命令提示符中的另外三个选项。

6.   [environment]::Version
7.   $PSVersionTable.CLRVersion
8.   gci 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -recurse | gp -name Version,Release -EA 0 |
     where { $_.PSChildName -match '^(?!S)\p{L}'} | select PSChildName, Version, Release

The last command (8) will give you all versions, including .NET 4.5.

最后一个命令 (8) 将为您提供所有版本,包括 .NET 4.5。

回答by AnandShanbhag

There is an easier way to get the exact version .NET version installed on your machine from a cmd prompt. Just follow the following instructions;

有一种更简单的方法可以从 cmd 提示符获取安装在您机器上的确切版本 .NET 版本。只需按照以下说明进行操作;

  1. Open the command prompt (i.e Windows + R → type "cmd").
  2. Type the following command, all on one line:
  1. 打开命令提示符(即 Windows + R → 键入“cmd”)。
  2. 键入以下命令,全部在一行中:

reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP"

reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP"

(This will list all the .NET versions.)

(这将列出所有 .NET 版本。)

  1. If you want to check the latest .NET 4 version.
  2. Type following instruction, on a single line:
  1. 如果您想查看最新的 .NET 4 版本。
  2. 在一行中键入以下说明:

reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\full" /v version

reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\full" /v version

Please find the attached image below to see how it is shown.

请找到下面的附加图片,看看它是如何显示的。

Enter image description here

在此处输入图片说明

回答by Phil Devaney

.NET Version Detectoris a GUI utility that displays which of the six(!) versions of the framework are installed.

.NET 版本检测器是一个 GUI 实用程序,可显示安装了框架的六个 (!) 版本中的哪一个。

回答by Sunimal Kaluarachchi

Before going to a command prompt, please follow these steps...

在进入命令提示符之前,请按照以下步骤操作...

Open My Computer→ double click "C:" drive → double click "Windows" → double click "Microsoft.NET" → double click "Framework" → Inside this folder, there will be folder(s) like "v1.0.3705" and/or "v2.0.50727" and/or "v3.5" and/or "v4.0.30319".

打开我的电脑→双击“ C:”驱动器→双击“ Windows”→双击“ Microsoft.NET”→双击“ Framework”→在这个文件夹里面,会有像“v1.0.3705”这样的文件夹和/或“v2.0.50727”和/或“v3.5”和/或“v4.0.30319”。

Your latest .NET version would be in the highest v number folder, so if v4.0.30319 is available that would hold your latest .NET framework. However, the v4.0.30319 does not mean that you have the .NET framework version 4.0. The v4.0.30319 is your Visual C# compiler version, therefore, in order to find the .NET framework version do the following.

您的最新 .NET 版本将位于最高的 v 编号文件夹中,因此如果 v4.0.30319 可用,它将包含您最新的 .NET 框架。但是,v4.0.30319 并不意味着您拥有 .NET 框架 4.0 版。v4.0.30319 是您的 Visual C# 编译器版本,因此,为了找到 .NET 框架版本,请执行以下操作。

Go to a command prompt and follow this path:

转到命令提示符并遵循以下路径:

C:\Windows\Microsoft.NET\Framework\v4.0.30319 (or whatever the highest v number folder)

C:\Windows\Microsoft.NET\Framework\v4.0.30319(或任何最高v号文件夹)

C:\Windows\Microsoft.NET\Framework\v4.0.30319 > csc.exe

C:\Windows\Microsoft.NET\Framework\v4.0.30319 > csc.exe

Output:

输出:

Microsoft (R) Visual C# Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5Copyright (C) Microsoft Corporation. All rights reserved.

Microsoft (R) Visual C# Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5版权所有 (C) Microsoft Corporation。版权所有。

Example below:

下面的例子:

Enter image description here

在此处输入图片说明

回答by adrianbanks

For the version of the framework that is installed, it varies depending on which service packs and hotfixes you have installed. Take a look at this MSDN pagefor more details. It suggests looking in %systemroot%\Microsoft.NET\Frameworkto get the version.

对于安装的框架版本,它因您安装的服务包和修补程序而异。请查看此 MSDN 页面以了解更多详细信息。它建议查看%systemroot%\Microsoft.NET\Framework以获取版本。

Environment.Versionwill programmatically give you the version of the CLR.

Environment.Version将以编程方式为您提供 CLR 的版本。

Note that this is the version of the CLR, and not necessarily the same as the latest version of the framework you have installed (.NET 3.0 and 3.5 both use v2 of the CLR).

请注意,这是 CLR 的版本,不一定与您安装的框架的最新版本相同(.NET 3.0 和 3.5 都使用 CLR 的 v2)。

回答by FelixAVeras

This answer is applicable to .NET Core only!

此答案仅适用于 .NET Core!

Typing dotnet --versionin your terminal of choice will print out the version of the .NET Core SDK in use.

dotnet --version在您选择的终端中键入将打印出正在使用的 .NET Core SDK 的版本。

Learn more about the dotnetcommand here.

此处了解有关该dotnet命令的更多信息。

回答by RBT

MSDN details it herevery nicely on how to check it from registry:

MSDN在这里非常详细地介绍了如何从注册表中检查它:

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.

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

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.

enter image description here

通过查看注册表查找 .NET Framework 版本(.NET Framework 1-4)

  1. 在开始菜单上,选择运行。
  2. 在“打开”框中,输入 regedit.exe。您必须具有管理凭据才能运行 regedit.exe。
  3. 在注册表编辑器中,打开以下子项:

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP

已安装的版本列在 NDP 子项下。版本号存储在版本条目中。对于 .NET Framework 4,版本条目位于 Client 或 Full 子项下(在 NDP 下),或在这两个子项下。

通过查看注册表查找 .NET Framework 版本(.NET Framework 4.5 及更高版本)

  1. 在开始菜单上,选择运行。
  2. 在打开框中,输入 regedit.exe。您必须具有管理凭据才能运行 regedit.exe。
  3. 在注册表编辑器中,打开以下子项:

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

请注意,完整子项的路径包括子项 Net Framework 而不是 .NET Framework

检查名为Release. Release DWORD 的存在表明该计算机上已安装 .NET Framework 4.5 或更高版本。

在此处输入图片说明

Note: The last row in the above snapshot which got clipped reads On all other OS versions: 461310. I tried my level best to avoid the information getting clipped while taking the screenshot but the table was way too big.

注意:上面快照中的最后一行被剪裁了On all other OS versions: 461310。我尽了最大努力避免在截取屏幕截图时信息被剪掉,但表格太大了。

回答by Michael Arnell

If you open a command prompt and type the following two commands, all framework versions that are installed on the current machine will be listed (each one is stored in a separate directory within this directory).

如果打开命令提示符并键入以下两个命令,则会列出当前机器上安装的所有框架版本(每个版本都存储在此目录中的单独目录中)。

cd %systemroot%\Microsoft.NET\Framework

dir /A:D

回答by Steve Junior

Just type the following in the command line:

只需在命令行中键入以下内容:

dir /b /ad /o-n %systemroot%\Microsoft.NET\Framework\v?.*

Your dotnet version will be shown as the highest number.

您的 dotnet 版本将显示为最高数字。

回答by Raghav

Here is the Power Shell script which I used by taking the reference of:

这是我通过参考使用的 Power Shell 脚本:

https://stackoverflow.com/a/3495491/148657

https://stackoverflow.com/a/3495491/148657

$Lookup = @{
    378389 = [version]'4.5'
    378675 = [version]'4.5.1'
    378758 = [version]'4.5.1'
    379893 = [version]'4.5.2'
    393295 = [version]'4.6'
    393297 = [version]'4.6'
    394254 = [version]'4.6.1'
    394271 = [version]'4.6.1'
    394802 = [version]'4.6.2'
    394806 = [version]'4.6.2'
    460798 = [version]'4.7'
    460805 = [version]'4.7'
    461308 = [version]'4.7.1'
    461310 = [version]'4.7.1'
    461808 = [version]'4.7.2'
    461814 = [version]'4.7.2'
    528040 = [version]'4.8'
    528049 = [version]'4.8'
}

# For One True framework (latest .NET 4x), change the Where-Oject match 
# to PSChildName -eq "Full":
Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -Recurse |
  Get-ItemProperty -name Version, Release -EA 0 |
  Where-Object { $_.PSChildName -match '^(?!S)\p{L}'} |
  Select-Object @{name = ".NET Framework"; expression = {$_.PSChildName}}, 
@{name = "Product"; expression = {$Lookup[$_.Release]}}, 
Version, Release

The above script makes use of the registry and gives us the Windows update number along with .Net Framework installed on a machine.

上面的脚本使用注册表并为我们提供 Windows 更新编号以及安装在机器上的 .Net Framework。

Reference: https://docs.microsoft.com/en-us/dotnet/framework/migration-guide/how-to-determine-which-versions-are-installed#to-find-net-framework-versions-by-querying-the-registry-in-code-net-framework-45-and-later

参考:https: //docs.microsoft.com/en-us/dotnet/framework/migration-guide/how-to-determine-which-versions-are-installed#to-find-net-framework-versions-by-查询注册表中的代码网络框架 45 及更高版本

Here are the results for the same when running that script on two different machines

以下是在两台不同机器上运行该脚本时的相同结果

  1. Where .NET 4.7.2 was already installed:
  1. 已经安装了 .NET 4.7.2 的地方:

enter image description here

在此处输入图片说明

  1. Where .NET 4.7.2 was not installed:
  1. 未安装 .NET 4.7.2 的地方:

enter image description here

在此处输入图片说明