.net - Windows 找不到最新安装的 .NET SDK

标签 .net windows .net-core dotnet-sdk

我已经成功安装了最新的 .NET SDK,但 Windows 无法识别它。这表现为以下故障之一:

  • dotnet --list-sdks不包括最新的 .NET SDK。
  • Windows x64 找不到 .NET 5 或 .NET 6。
  • 尝试打开项目时,Visual Studio 找不到最新的 SDK 或引发以下错误之一:

  • Project 'MyProject' load failed: The specified SDK "Microsoft.NET.Sdk" was not found.



  • Unable to locate the .NET SDK. Check that it is installed and that the version specified in global.json (if any) matches the installed version



  • The current .NET SDK does not support targeting .NET Core N.N. Either target .NET Core N.M or lower, or use a version of the .NET SDK that supports .NET Core N.N




  • 如何让 Windows 识别最新安装的 .NET SDK 版本?

    最佳答案

    运行 where dotnet从命令行。如果输出类似于:

    C:\Program Files (x86)\dotnet\dotnet.exe
    C:\Program Files\dotnet\dotnet.exe
    
    然后在某个时间安装了 32 位和 64 位版本的 SDK。
    32 bit --- C:\Program Files (x86)\dotnet\dotnet.exe
    62 bit --- C:\Program Files\dotnet\dotnet.exe
    
    计算机上安装的第一个 SDK 将 dotnet 路径放在系统路径中。任何不同位大小 SDK 的后续 SDK 安装也会将 dotnet 路径添加到系统路径,但在第一个 dotnet 路径之后。因此,默认情况下只有第一位大小的 SDK 可用,使用 path多变的。
    有两种方法可以解决问题:
  • 安装具有其他位大小的最新 SDK。这是最简单的解决方案。
  • 更改C:\Program Files (x86)\dotnet\dotnet.exe的顺序和 C:\Program Files\dotnet\dotnet.exe在系统环境变量路径中:

  • 选择windows键并输入Edit ,然后选择 编辑系统变量
    enter image description here
    选择 环境变量 上的按钮高级 标签:
    enter image description here
    选择 路径 > 编辑 系统变量 (不是用户变量)。
    enter image description here
    查找 C:\Program Files\dotnet\dotnet.exe 的条目(64 位)和 C:\Program Files\dotnet\dotnet.exe (32 位)并使用 搬家 向上按钮,更改为订单。下面是一个例子:
    enter image description here
    选择 好的 按钮,直到所有窗口都关闭。打开一个新的命令提示符并运行 where dotnet。
    来自 https://github.com/dotnet/core/issues/5962 的回答|
    更多详情请见 https://weblog.west-wind.com/posts/2019/Apr/20/Adventures-in-NET-SDK-Installation-SDKs-not-Showing-Up

    关于.net - Windows 找不到最新安装的 .NET SDK,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67049414/

    相关文章:

    asp.net - 通过别名从本地 IIS7 连接到 SQL Server 时出错

    python - 如何通过命令行在 gui 应用程序中填充文本框?

    css - 在 Windows 上配置 compass

    c# - Azure Function 启动的配置未被调用

    c# - 如何将一个 HttpClient 注入(inject)多个服务

    c# - 错误 1 ​​运算符 '*' 不能应用于类型 'method group' 和 'double' 的操作数

    c# - 如何删除字符串中两个单词之间的多余空格?

    c# - 单个模块化组件应该与其他组件一起工作(组件=模块)

    python - 我是否需要在计算机上安装 Python 才能在虚拟环境中运行代码?

    c# - 在具有.Net Core的内存数据库中不向实体集合添加数据