我如何知道安装了哪个版本的。net ?

我正在寻找一些像java -version一样简单的东西,我可以在命令提示符中键入,并告诉我当前安装的版本。

我最好补充一点,Visual Studio可能不会被安装——这通常是我想知道的关于客户端机器的事情。


当前回答

克利弗就是个很好的例子。只要在. net提示符中执行它,它就会列出所有可用的框架版本。

其他回答

下面是Power Shell脚本,我使用的参考:

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

上面的脚本使用了注册表,并提供了Windows更新号以及安装在机器上的. net Framework。

参考:https://learn.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

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

已经安装了。net 4.7.2的地方:

未安装。net 4.7.2的地方:

. net Version Detector是一个GUI实用程序,用于显示框架的六个(!)版本中哪个被安装了。

它完全像java。打开终端,执行以下命令

dotnet --version

MSDN详细介绍了如何从注册表中检查它:

To find .NET Framework versions by viewing the registry (.NET Framework 1-4) On the Start menu, choose Run. In the Open box, enter regedit.exe.You must have administrative credentials to run regedit.exe. 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) On the Start menu, choose Run. In the Open box, enter regedit.exe. You must have administrative credentials to run regedit.exe. 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.

注意:上面快照中被剪切的最后一行在所有其他操作系统版本上为:461310。我尽我最大的努力避免在截屏时信息被剪切,但表格太大了。

如果你在你的机器上安装了visual studio,

关于Microsoft Visual Studio,请访问帮助>

你会看到IDE正在使用的。net版本的信息。