我遗憾地在几天前运行了 Visual Studio 更新,更新后,我陷入了无法构建或调试 .NET MAUI 项目的状态。当我启动 Visual Studio 时,有一条消息显示
The solution requires .NET SDK Workloads that are not currently installed
。如果我单击“安装”按钮,系统会要求我输入 root 密码,但不会显示进度、成功或失败。我的包控制台显示以下内容:
Getting restore information for project /Users/adam/Projects/[redacted]/[redacted]/[redacted].csproj
/usr/local/share/dotnet/sdk/7.0.312/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.ImportWorkloads.targets(38,5) : error NETSDK1147: To build this project, the following workloads must be installed: maui-android
To install these workloads, run the following command: dotnet workload restore
Unable to create package spec for project. '/Users/adam/Projects/[redacted]/[redacted]/[redacted].csproj'
运行
sudo dotnet workload restore
运行成功,但似乎没有改变任何东西。如果我在终端中运行 dotnet workload list
,我会看到以下内容:
Installed Workload Id Manifest Version Installation Source
---------------------------------------------------------------------
maui-tizen 8.0.3/8.0.100 SDK 8.0.100
maui-maccatalyst 8.0.3/8.0.100 SDK 8.0.100
maui-ios 8.0.3/8.0.100 SDK 8.0.100
maui-android 8.0.3/8.0.100 SDK 8.0.100
ios 17.0.8490/8.0.100 SDK 8.0.100
maui 8.0.3/8.0.100 SDK 8.0.100
android 34.0.52/8.0.100 SDK 8.0.100
我尝试关闭 Visual Studio,通过
dotnet workload uninstall [workload id]
手动卸载每个工作负载,重新启动计算机,手动重新安装每个工作负载,再次重新启动计算机,然后再次打开 Visual Studio,但我仍然看到相同的错误。
我启用了 .NET 8 预览功能,正如 Matt Ward 在评论中所述,这解决了我的问题。