Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/maui-ci.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project>
<PropertyGroup Condition="'$(UseMaui)' == 'true' And '$(MauiCITargetFramework)' != ''">
<TargetFrameworks>$(MauiCITargetFramework)</TargetFrameworks>
</PropertyGroup>
</Project>
134 changes: 134 additions & 0 deletions .github/workflows/snippets5000.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,57 @@ permissions:
pull-requests: read

jobs:
maui-projects:
runs-on: ubuntu-latest
outputs:
samples: ${{ steps.samples.outputs.samples }}
steps:
- name: Harden Runner
uses: step-security/harden-runner@dc2769abcc0fcfbadfc1df54081c1608579ef6b2 # v2.22.2
with:
egress-policy: audit

- name: Find affected MAUI samples
id: samples
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8
env:
PR_NUMBER: ${{ github.event.pull_request.number || inputs.pull_request }}
with:
script: |
const files = await github.paginate(github.rest.pulls.listFiles, {
...context.repo,
pull_number: Number(process.env.PR_NUMBER)
});
const paths = files.flatMap(file => [file.filename, file.previous_filename].filter(Boolean));
const ciChanged = paths.some(path => ['.github/workflows/snippets5000.yml', '.github/maui-ci.targets'].includes(path));
const builds = [
{
version: '8.0', sdk: '8.0.427', macos: 'macos-15', xcode: '16.4',
projects: [
{ root: '8.0/MauiBlazorWeb/', path: '8.0/MauiBlazorWeb/MauiBlazorWeb.Maui/MauiBlazorWeb.Maui.csproj' }
]
},
{
version: '9.0', sdk: '9.0.320', macos: 'macos-26', xcode: '26.5',
projects: [
{ root: '9.0/MauiBlazorWeb/', path: '9.0/MauiBlazorWeb/MauiBlazorWeb/MauiBlazorWeb.csproj' },
{ root: '9.0/MauiBlazorWebIdentity/', path: '9.0/MauiBlazorWebIdentity/MauiBlazorWeb/MauiBlazorWeb/MauiBlazorWeb.csproj' }
]
},
{
version: '10.0', sdk: '10.0.400', macos: 'macos-26', xcode: '26.6',
projects: [
{ root: '10.0/MauiBlazorWebIdentity/', path: '10.0/MauiBlazorWebIdentity/MauiBlazorWeb/MauiBlazorWeb.csproj' }
]
}
];
for (const build of builds) {
build.projects = build.projects
.filter(project => ciChanged || paths.some(path => path.startsWith(project.root)))
.map(project => project.path);
}
core.setOutput('samples', JSON.stringify(builds.filter(build => build.projects.length > 0)));

snippets-build:
runs-on: windows-2022

Expand Down Expand Up @@ -60,3 +111,86 @@ jobs:
REPOSITORY_NAME: ${{ github.event.repository.name }}
run: |
dotnet run --project docs-tools\snippets5000\Snippets5000\Snippets5000.csproj -- --sourcepath "$env:GITHUB_WORKSPACE" --pullrequest "$env:PR_NUMBER" --owner "$env:REPOSITORY_OWNER" --repo "$env:REPOSITORY_NAME"

maui-build:
name: MAUI .NET ${{ matrix.sample.version }} (${{ matrix.platform }})
needs: maui-projects
if: needs.maui-projects.outputs.samples != '[]'
strategy:
fail-fast: false
matrix:
sample: ${{ fromJSON(needs.maui-projects.outputs.samples) }}
platform: [windows, macos]
runs-on: ${{ matrix.platform == 'windows' && 'windows-2022' || matrix.sample.macos }}
timeout-minutes: 45
defaults:
run:
shell: pwsh
env:
SDK_VERSION: ${{ matrix.sample.sdk }}
FRAMEWORK_VERSION: ${{ matrix.sample.version }}
PROJECTS: ${{ toJSON(matrix.sample.projects) }}
DEVELOPER_DIR: /Applications/Xcode_${{ matrix.sample.xcode }}.app/Contents/Developer

steps:
- name: Harden Runner
uses: step-security/harden-runner@dc2769abcc0fcfbadfc1df54081c1608579ef6b2 # v2.22.2
with:
egress-policy: audit

- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.event_name == 'workflow_dispatch' && format('refs/pull/{0}/merge', inputs.pull_request) || github.ref }}
persist-credentials: false

- name: Setup .NET
uses: actions/setup-dotnet@a98b56852c35b8e3190ac28c8c2271da59106c68 # v6.0.0
env:
DOTNET_INSTALL_DIR: ${{ runner.temp }}/dotnet
with:
dotnet-version: ${{ matrix.sample.sdk }}

- name: Select native-build SDK
run: dotnet new globaljson --sdk-version "$env:SDK_VERSION" --roll-forward disable

- name: Setup Java
if: runner.os == 'Windows'
uses: actions/setup-java@dded0888837ed1f317902acf8a20df0ad188d165 # v5.0.0
with:
distribution: temurin
java-version: '17'

- name: Display Xcode version
if: runner.os == 'macOS'
run: xcodebuild -version

- name: Install native workloads
run: |
$workloads = if ($IsWindows) { @('maui-android', 'maui-windows') } else { @('maui-ios', 'maui-maccatalyst') }
dotnet workload install @workloads --version "$env:SDK_VERSION"

- name: Build native apps
run: |
$projects = $env:PROJECTS | ConvertFrom-Json
$frameworks = if ($IsWindows) { @('android', 'windows10.0.19041.0') } else { @('ios', 'maccatalyst') }
$architecture = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString().ToLowerInvariant()
$targetsPath = Join-Path $env:GITHUB_WORKSPACE '.github/maui-ci.targets'
foreach ($project in $projects) {
foreach ($platform in $frameworks) {
$framework = "net$env:FRAMEWORK_VERSION-$platform"
$buildArguments = @($project, '--configuration', 'Debug', '--framework', $framework, "-p:MauiCITargetFramework=$framework", "-p:DirectoryBuildTargetsPath=$targetsPath")
if ($platform -eq 'android') {
dotnet build @buildArguments '-t:InstallAndroidDependencies' "-p:AndroidSdkDirectory=$env:ANDROID_HOME" "-p:JavaSdkDirectory=$env:JAVA_HOME" '-p:AcceptAndroidSDKLicenses=true'
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
} elseif ($platform -eq 'ios') {
$buildArguments += @("-p:RuntimeIdentifier=iossimulator-$architecture", '-p:EnableCodeSigning=false')
} elseif ($platform -eq 'maccatalyst') {
$buildArguments += @("-p:RuntimeIdentifier=maccatalyst-$architecture", '-p:EnableCodeSigning=false')
} else {
$buildArguments += '-p:WindowsPackageType=None'
}
dotnet build @buildArguments
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
}
}
4 changes: 4 additions & 0 deletions 10.0/MauiBlazorWebIdentity/snippets.5000.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"host": "custom",
"command": "dotnet build \"MauiBlazorWeb.Web/MauiBlazorWeb.Web.csproj\""
}
4 changes: 4 additions & 0 deletions 8.0/MauiBlazorWeb/snippets.5000.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"host": "custom",
"command": "dotnet build \"MauiBlazorWeb.Web/MauiBlazorWeb.Web.csproj\""
}
4 changes: 4 additions & 0 deletions 9.0/MauiBlazorWeb/snippets.5000.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"host": "custom",
"command": "dotnet build \"MauiBlazorWeb.Web/MauiBlazorWeb.Web.csproj\""
}
4 changes: 4 additions & 0 deletions 9.0/MauiBlazorWebIdentity/snippets.5000.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"host": "custom",
"command": "dotnet build \"MauiBlazorWeb/MauiBlazorWeb.Web/MauiBlazorWeb.Web.csproj\""
}
8 changes: 7 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ You need a basic understanding of [Git and GitHub.com](https://guides.github.com

The **Snippets 5000** workflow runs for pull requests that target `main`. It uses [Snippets5000](https://github.com/dotnet/docs-tools/tree/main/snippets5000) to discover and compile sample projects and solutions affected by changes to code files, Razor files, project files, solution files, or build configuration files such as `global.json` and `snippets.5000.json`.

Review compilation errors in the workflow logs and fix failures in the affected samples before merging. The workflow runs on Windows with the .NET 11 preview SDK and the .NET 10 SDK and runtime.
Review compilation errors in the workflow logs and fix failures in the affected samples before merging. The general snippet build runs on Windows with the .NET 11 preview SDK and the .NET 10 SDK and runtime.

For .NET MAUI Blazor Hybrid solutions, a `snippets.5000.json` file beside the solution uses the `custom` host to build the web project. This also compiles the referenced shared Razor class library and any hosted WebAssembly client.

Separate native-build jobs compile affected Hybrid samples for Android and Windows on Windows, and for iOS Simulator and Mac Catalyst on macOS. These jobs install matching .NET SDKs and MAUI workload sets, select compatible Xcode versions, and use `.github/maui-ci.targets` to limit native restore and build to the platform being checked without retargeting shared projects. Apple builds don't require distribution certificates, and no devices or simulators are launched. Changes to the workflow or CI targets file rebuild all four Hybrid samples; otherwise, only samples with changes under their solution directory are selected.

When adding another Hybrid sample, update the native-build matrix in `.github/workflows/snippets5000.yml`. Keep pinned SDK/workload sets and Xcode versions compatible when updating the toolchains.

To rerun the check manually, select **Actions** > **Snippets 5000** > **Run workflow** and enter the pull request number. The workflow checks out that pull request's merge ref and builds its affected samples.

Expand Down
Loading