2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[.NET 10] .NET MAUI を GitHub Actions で自動ビルド

Last updated at Posted at 2025-12-01

.NET MAUI Advent Calendar 2025 2日目の記事です。

概要

本記事は、タイトル通り GitHub Actions を用いて、.NET MAUI の自動ビルドをすることを目的としています。

Android と iOS の署名は含んでいません。署名の方法については、記事最後の参考資料を参照してください。

GitHub Actions で自動ビルド

1. 実行条件の設定

まずはじめに、GitHub Actions が実行される条件を決めます。

name: .NET MAUI Build

on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main
  workflow_dispatch:

今回は、main ブランチに push または PR されたとき、または手動で実行したとき (workflow_dispatch) に実行するように設定しました。

2. 環境設定

続いて、ビルド環境の準備を行います。

jobs:
  build:
    runs-on: ${{ (contains(matrix.tfm, 'maccatalyst') && 'macos-latest') || 'windows-latest' }}
    strategy:
      matrix:
        tfm: [net10.0-android, net10.0-ios, net10.0-maccatalyst, net10.0-windows10.0.19041.0]
      fail-fast: false

macOS アプリケーションは、macOS 上でしかビルドすることができないので、macos-latest を利用します。それ以外は、windows-latest でビルドできます。(Android 向けのビルドの際に ubuntu-latest を用いることでコスト削減できます!)

matrix を用いて、4種類のビルドを並列して処理します。

    steps:
      - name: Checkout
        uses: actions/checkout@v6

チェックアウトです。

      - name: Setup .NET
        uses: actions/setup-dotnet@v5
        with:
          dotnet-version: 10.0.x

.NET を準備します。バージョンは現在最新バージョンの .NET 10 です。

      - if: matrix.tfm == 'net10.0-maccatalyst'
        name: Setup Xcode latest
        uses: maxim-lobanov/setup-xcode@v1
        with:
          xcode-version: '26.1.1'

現在、macOS では XCode 26.1 以上が必要なのですが、macos-latest では XCode 16.4 が標準で選択されてしまい、以下のエラーが出ます:

/Users/runner/.dotnet/packs/Microsoft.MacCatalyst.Sdk.net10.0_26.1/26.1.10494/targets/Xamarin.Shared.Sdk.targets(2371,3): error : This version of .NET for MacCatalyst (26.1.10494) requires Xcode 26.1. The current version of Xcode is 16.4. Either install Xcode 26.1, or use a different version of .NET for MacCatalyst. See https://aka.ms/xcode-requirement for more information. [/Users/runner/work//_/src/_/_.csproj::TargetFramework=net10.0-maccatalyst]

このエラーを回避するため、明示的に 26.1.1 の使用を指定しています。

      - name: Install MAUI Workloads
        run: |
          dotnet workload install android --ignore-failed-sources
          dotnet workload install maui --ignore-failed-sources

最後に、workload のインストールを追加します。maui-android などの maui-* 系のすべてが必要ですが、maui に含まれているので大丈夫です。

これで、環境設定は終了です。

3. ビルド

ビルドです。

      - name: Restore Dependencies
        run: dotnet restore path/to/YourProject/A.csproj

      - name: Build MAUI App
        run: dotnet build path/to/YourProject/A.csproj -c Release -f ${{ matrix.tfm }} --no-restore

依存関係の修復を行い、-c Release でリリース、-f ${{ matrix.tfm }} でビルドターゲットを指定してビルドするだけです。

path/to/YourProject/A.csproj のところは、自分のプロジェクトのディレクトリに変更してください。

基本的には、これで終了です。

4. 完成品をアップロード

ビルド結果をダウンロードできるようにします。(任意)

      - if: matrix.tfm == 'net10.0-android'
        name: Android Artifact
        uses: actions/upload-artifact@v5
        with:
          name: android-ci-build
          path: path/to/YourProject/bin/Release/net10.0-android/*Signed.a*

      - if: matrix.tfm == 'net10.0-ios'
        name: iOS Artifact
        uses: actions/upload-artifact@v5
        with:
          name: ios-ci-build
          path: path/to/YourProject/bin/Release/net10.0-ios/

      - if: matrix.tfm == 'net10.0-maccatalyst'
        name: MacCatalyst Artifact
        uses: actions/upload-artifact@v5
        with:
          name: macos-ci-build
          path: path/to/YourProject/bin/Release/net10.0-maccatalyst/**/*.app/

      - if: matrix.tfm == 'net10.0-windows10.0.19041.0'
        name: Windows Artifact
        uses: actions/upload-artifact@v5
        with:
          name: windows-ci-build
          path: path/to/YourProject/bin/Release/net10.0-windows*/**/

長く見えますが、ターゲットによってアップロード時の名前やターゲットディレクトリを変えているだけです。

CI/CD が実行されたあと、Artifacts として GitHub に保存されます。ビルド結果をダウンロードできます。

以上です。

感想

1度設定しておくと、自動で動いてくれるので便利です!

.NET のバージョン (net10.0) や、最後のアップロード部分などは環境変数 (env:) としてまとめたほうが処理しやすいかもしれないです。

参考記事

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?