Skip to content

Add framework targeting to dotnet restore commands in multi-platform workflow#5

Draft
Copilot wants to merge 19 commits intomasterfrom
copilot/fix-github-actions-workflow
Draft

Add framework targeting to dotnet restore commands in multi-platform workflow#5
Copilot wants to merge 19 commits intomasterfrom
copilot/fix-github-actions-workflow

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 20, 2026

Multi-target MAUI projects fail CI when dotnet restore attempts to restore all framework dependencies on platform-specific runners (e.g., Windows runner fails with NETSDK1147: workloads must be installed: android).

Changes

Added -f <framework> parameter to dotnet restore commands in all three build jobs:

  • Android job: -f net10.0-android
  • Windows job: -f net10.0-windows10.0.19041.0
  • macOS job: -f net10.0-maccatalyst

Before:

- name: Restore dependencies
  run: dotnet restore zuoleme.csproj

After:

- name: Restore dependencies
  run: dotnet restore zuoleme.csproj -f net10.0-android

This scopes dependency restoration to each runner's target platform, eliminating cross-platform workload conflicts.

Original prompt

问题描述

当前的 GitHub Actions 工作流在 Windows 和其他平台上失败,错误信息为:

error NETSDK1147: To build this project, the following workloads must be installed: android

根本原因

在执行 dotnet restore zuoleme.csproj 时,由于项目文件包含多个目标框架(net10.0-android, net10.0-ios, net10.0-maccatalyst, net10.0-windows10.0.19041.0),dotnet 会尝试恢复所有平台的依赖。

例如:

  • Windows runner 尝试恢复 Android 依赖,但没有安装 Android workload
  • Ubuntu runner 尝试恢复 Windows/iOS 依赖,但无法在 Linux 上处理这些平台

解决方案

修改 .github/workflows/build.yml 文件,为每个平台的 restore、build 和 publish 命令添加 -f (framework) 参数,只针对特定的目标框架进行操作。

具体修改

1. Android 构建 (build-android job)

- name: Restore dependencies
  run: dotnet restore zuoleme.csproj -f net10.0-android

- name: Build Android APK
  run: dotnet build zuoleme.csproj -c Release -f net10.0-android /p:AndroidPackageFormat=apk

- name: Build Android AAB
  run: dotnet publish zuoleme.csproj -c Release -f net10.0-android /p:AndroidPackageFormat=aab

2. Windows 构建 (build-windows job)

- name: Restore dependencies
  run: dotnet restore zuoleme.csproj -f net10.0-windows10.0.19041.0

- name: Build Windows MSIX
  run: dotnet publish zuoleme.csproj -c Release -f net10.0-windows10.0.19041.0 -p:RuntimeIdentifierOverride=win10-x64

3. macOS 构建 (build-macos job)

- name: Restore dependencies
  run: dotnet restore zuoleme.csproj -f net10.0-maccatalyst

- name: Build macOS Catalyst
  run: dotnet build zuoleme.csproj -c Release -f net10.0-maccatalyst

- name: Publish macOS Catalyst
  run: dotnet publish zuoleme.csproj -c Release -f net10.0-maccatalyst -p:CreatePackage=true

预期结果

修复后,每个 runner 只会处理其对应平台的依赖和构建,避免交叉依赖问题,所有三个平台的构建应该能够成功完成。

要修改的文件

.github/workflows/build.yml - 在第 37、76 和 104 行的 restore 命令中添加框架参数

This pull request was created from Copilot chat.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

… commands

Co-authored-by: Chenfyuan <13745755+Chenfyuan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix GitHub Actions workflow for platform-specific builds Add framework targeting to dotnet restore commands in multi-platform workflow Jan 20, 2026
Copilot AI requested a review from Chenfyuan January 20, 2026 05:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants