Windows 或 Visual Studio 找不到最新安装的 .NET SDK [英] Windows or Visual Studio can't find the latest installed .NET SDK

查看:75
本文介绍了Windows 或 Visual Studio 找不到最新安装的 .NET SDK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

      项目MyProject"加载失败:指定的 SDKMicrosoft.NET.Sdk"未找到.

    • <块引用>

      无法找到 .NET SDK.检查它是否已安装以及 global.json 中指定的版本(如果有)是否与安装的版本匹配

    • <块引用>

      当前的 .NET SDK 不支持面向 .NET Core N.N.面向 .NET Core N.M 或更低版本,或使用支持 .NET Core N.N 的 .NET SDK 版本

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

解决方案

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

C:Program Files (x86)dotnetdotnet.exeC:Program Filesdotnetdotnet.exe

然后在某个时间安装了 32 位和 64 位版本的 SDK.

32 位 --- C:Program Files (x86)dotnetdotnet.exe62 位 --- C:Program Filesdotnetdotnet.exe

计算机上安装的第一个 SDK 将 dotnet 路径放在系统路径中.任何不同位大小 SDK 的后续 SDK 安装也会将 dotnet 路径添加到系统路径,但在第一个 dotnet 路径之后.因此,默认情况下只有第一位大小的 SDK 可用,使用 path 变量.

有两种方法可以解决此问题:

  1. 安装具有其他位大小的最新 SDK.这是最简单的解决方案.
  2. 更改C:Program Files (x86)dotnetdotnet.exeC:Program Filesdotnetdotnet.exe在系统中的顺序环境变量路径:

选择windows键并输入Edit,然后选择Edit the system variables

选择高级标签上的环境变量按钮:

选择路径 >在系统变量(不是用户变量)下编辑.

查找 C:Program Filesdotnetdotnet.exe(64 位)和 C:Program Filesdotnetdotnet.exe(32位)并使用上移按钮,更改顺序.举个例子:

选择确定按钮,直到所有窗口都关闭.打开一个新的命令提示符并运行 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

I've successfully installed the latest .NET SDK, but Windows doesn't recognize it. This is manifested by one of the following failures:

  • dotnet --list-sdks doesn't include the latest .NET SDK.
  • Windows x64 can't find .NET 5 or .NET 6.
  • Visual Studio can't find the latest SDK or throws one of the following errors when trying to open a project:
    • 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

How can I get Windows to recognize the latest installed version of the .NET SDK?

解决方案

Run where dotnet from the command line. If the output is similar to:

C:Program Files (x86)dotnetdotnet.exe
C:Program Filesdotnetdotnet.exe

Then both the 32-bit and 64-bit versions of the SDK have been installed at some time.

32 bit --- C:Program Files (x86)dotnetdotnet.exe
62 bit --- C:Program Filesdotnetdotnet.exe

The first SDK installed on the computer puts the dotnet path in the system path. Any subsequent SDK install of a different bit size SDK also adds dotnet path to the system path, but after the first dotnet path. Therefore, only SDK's of the first bit size are available by default, using the path variable.

There are two approaches to fixing the problem:

  1. Install the latest SDK with the other bit size. This is the easiest solution.
  2. Change the order of C:Program Files (x86)dotnetdotnet.exe and C:Program Filesdotnetdotnet.exe in the System environment variables path:

Select the windows key and enter Edit, then select Edit the system variables

Select the Environment Variables button on the Advanced tab:

Select the Path > Edit under System variables (not User variables).

Find the entries for C:Program Filesdotnetdotnet.exe (64 bit) and C:Program Filesdotnetdotnet.exe (32 bit) and using the Move up button, change to order. Here's an example:

Select the OK button until all the windows are closed. Open a new command prompt and run where dotnet.

Answer from https://github.com/dotnet/core/issues/5962 More details at https://weblog.west-wind.com/posts/2019/Apr/20/Adventures-in-NET-SDK-Installation-SDKs-not-Showing-Up

这篇关于Windows 或 Visual Studio 找不到最新安装的 .NET SDK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆