来自微软模板的.NET MAUI项目在使用dotnet build -c Release --no-restore构建时会失败

移动开发 2026-07-10

在VS 2026中,我新建了一个项目,使用的是C#的 MAUI模板。

随后,我打开一个命令行终端并执行:

  1. Restore packages

dotnet rstore

Restore complete (1,4s) 2. Build

dotnet build -c Release --no-restore

它失败了。

$ dotnet restore
Restore complete (4,5s)

$ dotnet build -c Release --no-restore
  MauiApp2 net10.0-maccatalyst maccatalyst-x64 succeeded (19,9s) → MauiApp2\bin\Release\net10.0-maccatalyst\maccatalyst-x64\MauiApp2.dll
  MauiApp2 net10.0-maccatalyst maccatalyst-arm64 failed with 1 error(s) (0,1s)
    C:\Program Files\dotnet\sdk\10.0.201\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error NETSDK1047: Assets file 'D:\Programming\Learning\learning.MAUI\poc.maui.template.build\MauiApp2\obj\project.assets.json' doesn't have a target for 'net10.0-maccatalyst/maccatalyst-arm64'. Ensure that restore has run and that you have included 'net10.0-maccatalyst' in the TargetFrameworks for your project. You may also need to include 'maccatalyst-arm64' in your project's RuntimeIdentifiers.
  MauiApp2 net10.0-ios iossimulator-x64 succeeded (22,4s) → MauiApp2\bin\Release\net10.0-ios\iossimulator-x64\MauiApp2.dll
  MauiApp2 net10.0-windows10.0.19041.0 win-x64 succeeded (60,1s) → MauiApp2\bin\Release\net10.0-windows10.0.19041.0\win-x64\MauiApp2.dll
  MauiApp2 net10.0-android succeeded (170,4s) → MauiApp2\bin\Release\net10.0-android\MauiApp2.dll

说明:
dotnet build 工作正常。
dotnet restore 紧接着 dotnet build -c Release--no-restore 会导致错误+ 警告(关于XAML自动生成的类)

我需要在GitHub Actions(Windows机器上)中执行这些命令。

为什么在一个基础模板上,dotnet build -c Release --no-restore 的行为与 dotnet build 不同?

enter image description here

用于复现错误的仓库

https://github.com/alex-piccione/poc.maui.template.build/blob/main/README.md

在本地Windows机器上:

  • dotnet build 可以正常工作:
  • dotnet restore 接着 dotnet build -c Release --no-restore,由于关于 'net10.0-maccatalyst' 的问题会失败,同时还会对使用已废弃的类(XAML自动生成)发出大量警告。

enter image description here

enter image description here

解决方案

目前没有解决方案(截至2026年 4月 9日)。

我向微软提交了一个工单,问题已被确认,并已在MAUI的 GitHub仓库中提交为一个issue:https://github.com/dotnet/maui/issues/34767

站内所有文章版权归属LeftHeroAI导航站,无授权禁止任何主体转载、抄袭、复制内容,亦不得私自架设镜像站点。一经侵权,本站将通过法律途径追责。

相关文章