【问题标题】:dotnet build stopped working after VS 2022 upgradeVS 2022 升级后 dotnet build 停止工作
【发布时间】:2021-12-24 07:46:20
【问题描述】:

我将 Visual Studio Community 升级到最终版本,但它停止工作。具体来说,我可以生成一个新项目,但是当我尝试加载它时,它给了我一个错误

关键项目“SdkTest”加载失败| [MSB4236] 找不到指定的 SDK“Microsoft.NET.Sdk.Web”。 ...\SdkTest.csproj

即使构建和运行正常

我在 VS2022 上运行了“修复”,现在它似乎可以在 Visual Studio 中运行了。但是,dotnet --info 不显示 任何 SDK;只有运行时;和dotnet builddotnet new 给出错误:

C:\Code>dotnet new console -o myapp
Could not execute because the application was not found or a compatible .NET SDK is not installed.
Possible reasons for this include:
   * You intended to execute a .NET program:
     The application 'new' does not exist.
   * You intended to execute a .NET SDK command:
     It was not possible to find any installed .NET SDKs.
     Install a .NET SDK from:
       https://aka.ms/dotnet-download

我什至重新安装了 .NET 6,并在应用程序列表中看到了它(以及较旧的 SDK)。我检查了路径,我看到了我希望看到的一切:

C:\Program Files (x86)\dotnet\
C:\Program Files\dotnet\
C:\Users\me\.dotnet\tools

我正在运行 Windows 11。

【问题讨论】:

  • Program files 应该在Program files (x86) 之前,这是已知的错误。 Fix
  • @JL0PD - 你想把它作为答案吗?我会欣然接受。我在谷歌上搜索各种搜索词 - 从来没有偶然发现那个 github 问题

标签: .net-core msbuild visual-studio-2022


【解决方案1】:

在 VS2022 安装中是known bug

问题是您访问的dotnet 位于Program Files(x86)/dotnet 中,但所有sdk 都位于Program Files/dotnet 中。您只需编辑PATH 环境变量,使Program Files/dotnet 位于Program Files(x86)/dotnet 之前。如果您在用户环境变量中没有看到Program Files(x86)/dotnet(这很可能发生),请编辑系统环境变量(位于下方)

截图示例:https://stackoverflow.com/a/44272417/10339675

【讨论】:

  • 顺便说一句,当我在等待这个答案时 - 我下载并安装了通常用于 CI 服务器的“dotnet-install 脚本”。它将另一个 dotnet 安装到 `AppData\Local\Microsoft\dotnet` 中,并首先将其添加到 PATH 中。这也使它起作用。显然,您的答案是更好的方法 - 它解释了为什么我遇到了问题。谢谢
  • 另外,来自微软的一个很好的解释:stackoverflow.com/questions/63746838/…
猜你喜欢
  • 2022-09-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-14
  • 2019-08-11
  • 2021-07-05
  • 1970-01-01
  • 2021-08-12
相关资源
最近更新 更多