首页 > 解决方案 > VS 2022 升级后 dotnet build 停止工作

问题描述

我将 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。

标签: .net-coremsbuildvisual-studio-2022

解决方案


这是 VS2022 安装中的已知错误

问题是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


推荐阅读