如何检查是否已安装 .NET

本文介绍如何检查计算机上安装的 .NET 运行时和 SDK 的版本。 如果拥有集成开发环境(如 Visual Studio),则可能已安装 .NET。

安装 SDK 便会安装相应的运行时。

如果本文中的任何命令失败,则未安装运行时或 SDK。 有关详细信息,请参阅 WindowsmacOSLinux 的安装文章。

检查 SDK 版本

可使用终端查看当前安装的 .NET SDK 版本。 打开终端并运行以下命令。

dotnet --list-sdks

将获得类似于下面的输出。

3.1.424 [C:\program files\dotnet\sdk]
5.0.100 [C:\program files\dotnet\sdk]
6.0.402 [C:\program files\dotnet\sdk]
7.0.404 [C:\program files\dotnet\sdk]
8.0.100 [C:\program files\dotnet\sdk]
3.1.424 [/home/user/dotnet/sdk]
5.0.100 [/home/user/dotnet/sdk]
6.0.402 [/home/user/dotnet/sdk]
7.0.404 [/home/user/dotnet/sdk]
8.0.100 [/home/user/dotnet/sdk]
3.1.424 [/usr/local/share/dotnet/sdk]
5.0.100 [/usr/local/share/dotnet/sdk]
6.0.402 [/usr/local/share/dotnet/sdk]
7.0.404 [/usr/local/share/dotnet/sdk]
8.0.100 [/usr/local/share/dotnet/sdk]

检查运行时版本

可使用以下命令查看当前安装的 .NET 运行时版本。

dotnet --list-runtimes

将获得类似于下面的输出。

Microsoft.AspNetCore.App 3.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.1.30 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.30 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.AspNetCore.All 2.1.7 [/usr/lib/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.13 [/usr/lib/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.7 [/usr/lib/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.13 [/usr/lib/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.0 [/usr/lib/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.0 [/usr/lib/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.0 [/usr/lib/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.7 [/usr/lib/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.13 [/usr/lib/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.0 [/usr/lib/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.0 [/usr/lib/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.0 [/usr/lib/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.0 [/usr/lib/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.0 [/usr/lib/dotnet/shared/Microsoft.NETCore.App]
Microsoft.AspNetCore.All 2.1.7 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.13 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.7 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.13 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.7 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.13 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

检查安装文件夹

可以安装 .NET,但不能将其添加到操作系统或用户配置文件的 PATH 变量。 在这种情况下,前面几节中的命令可能不起作用。 作为替代方法,可以检查 .NET 安装文件夹是否存在。

从安装程序或脚本安装 .NET 时,会将其安装到标准文件夹中。 大多数时候,安装 .NET 时使用的安装程序或脚本会让你选择安装到另一个文件夹。 如果选择安装到其他文件夹,请调整文件夹路径的开头。

  • dotnet executable
    C:\program files\dotnet\dotnet.exe

  • .NET SDK
    C:\program files\dotnet\sdk\{version}\

  • .NET 运行时
    C:\program files\dotnet\shared\{runtime-type}\{version}\

  • dotnet executable
    /home/user/.dotnet/dotnet
    /usr/lib/dotnet/dotnet
    /usr/share/dotnet/dotnet\

  • .NET SDK
    /home/user/.dotnet/sdk/{version}/
    /usr/lib/dotnet/sdk/{version}/
    /usr/share/dotnet/sdk/{version}/\

  • .NET 运行时
    /home/user/.dotnet/shared/{runtime-type}/{version}/
    /usr/lib/dotnet/shared/{runtime-type}/{version}/
    /usr/share/dotnet/shared/{runtime-type}/{version}/\

  • dotnet executable
    /usr/local/share/dotnet/dotnet

  • .NET SDK
    /usr/local/share/dotnet/sdk/{version}/

  • .NET Runtime
    /usr/local/share/dotnet/shared/{runtime-type}/{version}/

详细信息

可通过命令 dotnet --info 查看 SDK 版本和运行时版本。 你还将获得其他环境相关信息,如操作系统版本和运行时标识符 (RID)。

后续步骤

请参阅