Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
c009f57
[build] Use dotnetup and standard solution build entrypoints
simonrozsival Nov 9, 2026
cadf1ae
[build] Fix shared SDK CI workload setup and forwarding
simonrozsival Nov 9, 2026
d03ea27
[build] Skip installation for empty workload dependency plans
simonrozsival Nov 9, 2026
6579a29
[build] Resolve workloads with the installed SDK version
simonrozsival Nov 10, 2026
b9818be
[build] Normalize workload dependency package roots
simonrozsival Nov 10, 2026
194dfb0
[build] Clamp future workload pack timestamps
simonrozsival Nov 10, 2026
1c69c62
[build] Use canonical packed workload filenames
simonrozsival Nov 10, 2026
445169e
[docs] Align local-build guidance after rebase
simonrozsival Nov 18, 2026
50bb21f
[ci] Install older runtimes instead of additional SDKs
simonrozsival Nov 24, 2026
14c2931
[ci] Make shared dotnetup installation noninteractive
simonrozsival Nov 24, 2026
a8795b3
[build] Allow Maestro to advance the shared SDK pin
simonrozsival Nov 24, 2026
4b1ef03
[build] Respect solution packing and project selection
simonrozsival Nov 25, 2026
d0aa1bf
[build] Make solution Clean preserve shared tooling
simonrozsival Nov 25, 2026
c72a4b3
[build] Skip WorkloadDependencies for the local workload
simonrozsival Nov 25, 2026
a9806c0
[build] Fix no-op incrementality of local SDK targets
simonrozsival Nov 25, 2026
6cc11e7
[build] Skip extra API builds when up to date
simonrozsival Nov 25, 2026
e1583cf
[build] Reduce local workload setup overhead
simonrozsival Nov 25, 2026
691e8c6
[build] Fix SourceLink in packed-ref worktrees
simonrozsival Nov 25, 2026
e5a254b
[ci] Forward SDK package helpers through dotnetup
simonrozsival Nov 25, 2026
b16dc10
[build] Keep local workloads aligned with the pinned SDK
simonrozsival Nov 26, 2026
a1a65dd
[build] Integrate updated SDK build entry points
simonrozsival Nov 26, 2026
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
47 changes: 22 additions & 25 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,31 @@
**Build System:** MSBuild + .NET Arcade SDK + CMake (native)

## Essential Commands
- **Build the local SDK:** `make prepare && make leeroy` (not `make all`) or `build.cmd`; see the `local-build` skill
- **Test with local build:** `dotnet-local.sh`/`dotnet-local.cmd` (prefers `bin/Release` when present)
- **Install SDK:** `dotnetup sdk install` (reads the exact pin in `global.json`)
- **Build:** `dotnetup dotnet build Microsoft.Android.slnx`
- **Package:** `dotnetup dotnet pack Microsoft.Android.slnx` (defaults to Release; use `--no-build -c Debug` to package an existing Debug build)
- **Test with local build:** `dotnet-local.sh`/`dotnet-local.cmd`
- **Run tests:** `dotnet-local.cmd test bin/TestDebug/net11.0/Xamarin.Android.Build.Tests.dll --filter Name~TestName`
- **Device tests:** `dotnet-local.cmd test bin/TestDebug/MSBuildDeviceIntegration/net11.0/MSBuildDeviceIntegration.dll` (`android-devices` skill)

The test assembly framework comes from `DotNetStableTargetFramework` in `Directory.Build.props`. On macOS/Linux, use `./dotnet-local.sh` instead of `dotnet-local.cmd`.

Use `dotnetup dotnet` for repository commands; only dotnetup needs to be on `PATH`.
`dotnet-local` adds worktree-local workload paths. It defaults to Debug; set
`CONFIGURATION=Release` for Release workloads (`-c` is only forwarded).
Never install development workloads into the shared SDK with `dotnet workload install`.
See [`eng/README.md`](../eng/README.md#sdk-selection-and-ci) for SDK pin updates and CI setup.

### Shared Android tooling

The in-tree Android tools libraries include SDK/JDK discovery (`AndroidSdkInfo`, `JdkInfo`, SDK manifest parsing, `AdbRunner`, `EmulatorRunner`) and MSBuild task infrastructure (`AndroidTask`, `AndroidToolTask`, `AsyncTask`, `Files`, `ProcessUtils`, `FileUtil`, `MemoryStreamPool`). They target `netstandard2.0` and/or modern .NET, so verify API availability across all target frameworks before using newer BCL APIs. Prefer `ANDROID_HOME` for new Android SDK environment handling; `ANDROID_SDK_ROOT` is deprecated and should only remain for compatibility.

Useful focused checks:
```sh
dotnet build src/Microsoft.Android.Build.BaseTasks/Microsoft.Android.Build.BaseTasks.csproj
dotnet build src/Xamarin.Android.Tools.AndroidSdk/Xamarin.Android.Tools.AndroidSdk.csproj
dotnet test tests/Xamarin.Android.Tools.AndroidSdk-Tests/Xamarin.Android.Tools.AndroidSdk-Tests.csproj -p:AndroidToolsDisableMultiTargeting=false -p:DotNetTargetFrameworkVersion=10.0
dotnet test tests/Microsoft.Android.Build.BaseTasks-Tests/Microsoft.Android.Build.BaseTasks-Tests.csproj
dotnetup dotnet build src/Microsoft.Android.Build.BaseTasks/Microsoft.Android.Build.BaseTasks.csproj
dotnetup dotnet build src/Xamarin.Android.Tools.AndroidSdk/Xamarin.Android.Tools.AndroidSdk.csproj
dotnetup dotnet test tests/Xamarin.Android.Tools.AndroidSdk-Tests/Xamarin.Android.Tools.AndroidSdk-Tests.csproj -p:AndroidToolsDisableMultiTargeting=false -p:DotNetTargetFrameworkVersion=10.0
dotnetup dotnet test tests/Microsoft.Android.Build.BaseTasks-Tests/Microsoft.Android.Build.BaseTasks-Tests.csproj
```

## Working Principles
Expand Down Expand Up @@ -215,12 +223,13 @@ try {

### Validate locally before pushing

**Build and test code changes locally before pushing or opening a PR.** Building the full SDK is a normal part of development, not something to avoid because it is assumed to be slow. CI provides additional coverage; it is not a substitute for local validation or the first place to discover whether a change builds.
**Build and test code changes locally before pushing or opening a PR.** CI is
additional coverage, not a substitute. Do not skip validation because of presumed
build time or debug regressions through repeated CI runs.

- **Prepare and build the SDK when needed.** On macOS/Linux, run `make prepare && make leeroy`; on Windows, run `build.cmd`. Use the configuration required by the affected tests (for example, `make prepare CONFIGURATION=Release && make leeroy CONFIGURATION=Release`). A missing local SDK is a reason to prepare and build it, not to offer skipping full-build tests. Rebuild after source changes so tests exercise the updated SDK, not stale binaries.
- **Run the relevant tests against the locally built SDK.** Use `dotnet-local.sh`/`dotnet-local.cmd` for full-build tests; standalone tests can use plain `dotnet test`. Consult `.github/skills/tests/SKILL.md` and its test catalog for commands and coverage. Start with focused tests while iterating, then expand coverage for cross-cutting changes. Runtime, JNI, and native changes need the relevant on-device tests, not just host-side unit tests; exercise the affected runtime, ABI, and build properties.
- **Do not ask whether to skip validation solely because of presumed build time.** Proceed with the required local build and tests unless the user explicitly limits validation or a concrete environment constraint prevents it. If blocked, report the exact command, failure or missing prerequisite, and what remains unvalidated. Do not push known regressions or use repeated CI runs to debug them.
- **Record actual validation results.** Report the build/test commands and their outcomes when handing off code changes or preparing a PR. Documentation-only changes do not require SDK compilation or device tests.
- Build missing workloads and rebuild after source changes, using the configuration required by the tests.
- Follow `.github/skills/tests/SKILL.md` for commands and coverage. Runtime, JNI, and native changes require relevant on-device tests with the affected runtime, ABI, and build properties.
- Report exact build/test commands and outcomes. If blocked, report the failed command, missing prerequisite, and unvalidated coverage. Documentation-only changes need no SDK build or device tests.
- **Parallel sessions:** run at most one or two full SDK builds per host, give each device run its own emulator or serial, never stop processes or `adb` you didn't start, and queue heavy work instead of inventing lease protocols.

**Modifying project files in tests:** Never use `File.WriteAllText()` directly to update project source files. Instead, use the `Xamarin.ProjectTools` infrastructure:
Expand Down Expand Up @@ -256,19 +265,7 @@ This pattern ensures proper encoding, timestamps, and file attributes are handle

When diagnosing runtime, build, or test failures, follow these practices. They exist because the .NET ↔ JNI ↔ C++ ↔ generated-native stack is loosely coupled and static reasoning alone is unreliable.

- **Reproduce CI failures locally — do not iterate through CI.** A clean local test cycle is minutes; a CI iteration is hours. Run device tests the same way CI does:
```bash
make prepare CONFIGURATION=Release && make leeroy CONFIGURATION=Release
./dotnet-local.sh build -t:Install -c Release \
tests/Mono.Android-Tests/Mono.Android-Tests/Mono.Android.NET-Tests.csproj
(
cd tests/Mono.Android-Tests/Mono.Android-Tests
../../../dotnet-local.sh test Mono.Android.NET-Tests.csproj --no-build -c Release \
--report-trx --results-directory ../../../bin/TestRelease/TestResults
)
```
On Windows, use `build.cmd` and `dotnet-local.cmd` instead of `make`/`dotnet-local.sh`.
Results land in `.trx` files under `bin/TestRelease/TestResults`.
- **Reproduce CI failures locally.** Follow the tests skill's on-device instructions with the failing CI configuration, runtime, ABI, and build properties. Use a Visual Studio Developer Command Prompt on Windows.

- **When the build gets into a weird state, delete `bin/` and `obj/` and rebuild from scratch.** Stale incremental output causes phantom errors. See **Troubleshooting → Build** below.

Expand All @@ -281,7 +278,7 @@ When diagnosing runtime, build, or test failures, follow these practices. They e
- **Confirm the runtime that ran.** `PublishAot=true` in Debug still uses CoreCLR unless `Optimize=true` or publishing; check `_AndroidRuntime` before claiming NativeAOT coverage.

## Troubleshooting
- **Build:** Clean `bin/`+`obj/`, check Android SDK/NDK, `make clean && make prepare && make leeroy`; see the `local-build` skill for stalls, SourceLink warnings, and disk space
- **Build:** Check Android SDK/NDK, run `dotnetup sdk install`, then `dotnetup dotnet build Microsoft.Android.slnx`; use `dotnetup dotnet clean Microsoft.Android.slnx` when cleaning is necessary.
- **MSBuild:** Test in isolation, validate inputs
- **Device:** Use update directories for rapid Debug iteration; see the `android-devices` skill
- **Performance:** See `../Documentation/guides/profiling.md` and `../Documentation/guides/tracing.md`
27 changes: 14 additions & 13 deletions .github/skills/local-build/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
name: local-build
description: >-
Builds the local dotnet/android SDK and fixes local build problems. Use
before full-build or device tests, when `bin/<Configuration>/dotnet` is
missing or stale, when `make` or `dotnet-local.sh` builds fail, stall, or run
before full-build or device tests, when `bin/<Configuration>/workload` is
missing or stale, when `dotnetup dotnet` or `dotnet-local.sh` builds fail, stall, or run
out of disk, and when several sessions build on one host.
---

Expand All @@ -12,38 +12,39 @@ description: >-
## Build

```bash
make prepare CONFIGURATION=Debug && make leeroy CONFIGURATION=Debug # = make jenkins, as CI does
dotnetup sdk install
dotnetup dotnet build Microsoft.Android.slnx -c Debug -bl:bin/BuildDebug/local-build.binlog
```

On Windows, run `build.cmd`.
Use the same commands on Windows.

- Don't use `make all`. It skips `BuildExtraApiLevels`, so `ConfigureLocalWorkload` fails.
- Pass extra flags via `MSBUILD_ARGS='...'`. Overriding `MSBUILD_FLAGS` drops `-p:Configuration`.
- On failure, read `bin/Build<cfg>/msbuild-*.binlog` (for example `binlogtool search bin/Build<cfg>/msbuild-*.binlog "error"`; see "Analysis commands" in `.github/skills/ci-status/references/binlog-analysis.md`) rather than re-running verbosely.
- `dotnet-local.sh` runs `bin/Release` whenever it exists, regardless of `CONFIGURATION`. Delete the configuration you aren't using, or call `bin/<cfg>/dotnet/dotnet` directly with the same workload roots the wrapper sets: `DOTNETSDK_WORKLOAD_MANIFEST_ROOTS="$PWD/bin/<cfg>/lib/sdk-manifests" DOTNETSDK_WORKLOAD_PACK_ROOTS="$PWD/bin/<cfg>/lib"`.
- An existing `bin/<cfg>/dotnet` only means `make prepare` ran, not that the SDK was built.
- The solution build prepares prerequisites, builds extra API levels, and configures the local workload.
- Pass extra MSBuild flags directly to `dotnetup dotnet build`.
- On failure, read the captured `bin/Build<cfg>/local-build.binlog` (see "Analysis commands" in `.github/skills/ci-status/references/binlog-analysis.md`) rather than re-running verbosely.
- `dotnet-local.sh` defaults to Debug workloads; set `CONFIGURATION=Release` for Release workloads and also pass `-c Release` to build/test commands. On Windows, set the environment variable and use `dotnet-local.cmd`.
- An installed shared SDK does not mean the repository's Android packs or test assemblies have been built.

## Rebuild only what changed

| Change in | Command |
|---|---|
| `src/Xamarin.Android.Build.Tasks/` (tasks, `.targets`) | `./dotnet-local.sh build src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj -c <cfg>`, where `<cfg>` matches the SDK and tests (it defaults to Debug and outputs into that configuration's local SDK) |
| Standalone libraries (`Microsoft.Android.Build.BaseTasks`, `Xamarin.Android.Tools.AndroidSdk`, `Microsoft.Android.Build.Tasks`, Java.Interop tooling, `generator`) | `dotnet build` / `dotnet test` the project; no local SDK needed |
| Bindings, native runtime, packaging, or unsure | `make leeroy CONFIGURATION=<cfg>` (incremental; `CONFIGURATION` defaults to Debug) |
| Standalone libraries (`Microsoft.Android.Build.BaseTasks`, `Xamarin.Android.Tools.AndroidSdk`, `Microsoft.Android.Build.Tasks`, Java.Interop tooling, `generator`) | `dotnetup dotnet build` / `dotnetup dotnet test` the project; no local Android build needed |
| Bindings, native runtime, packaging, or unsure | `dotnetup dotnet build Microsoft.Android.slnx -c <cfg>` (incremental; configuration defaults to Debug) |

## Known issues

| Symptom | Fix |
|---|---|
| No output for 10+ minutes, idle MSBuild nodes | Stop only your build, then run `DOTNET_CLI_USE_MSBUILD_SERVER=0 MSBUILDDISABLENODEREUSE=1 make leeroy CONFIGURATION=<cfg> MSBUILD_ARGS='-nr:false -m:1 -p:UseSharedCompilation=false'` |
| No output for 10+ minutes, idle MSBuild nodes | Stop only your build, then run `DOTNET_CLI_USE_MSBUILD_SERVER=0 MSBUILDDISABLENODEREUSE=1 dotnetup dotnet build Microsoft.Android.slnx -c <cfg> -nr:false -m:1 -p:UseSharedCompilation=false` |
| SourceLink `Repository has no commit` in a fresh worktree | Commit on the branch, or for local-only checks pass `-p:EnableSourceLink=false -p:EnableSourceControlManagerQueries=false`. Don't change this in source. |
| Phantom errors after switching branches | `rm -rf bin obj`, then rebuild |
| `No space left on device` | Delete `bin/` and `obj/` in unused worktrees. `~/android-toolchain` is already shared; don't redirect it. |

## Parallel sessions on one host

- Build the full SDK only when the change requires it (see the validation table in the `tests` skill).
- Run at most one or two full builds at once; cap others with `MSBUILD_ARGS='-m:4'`.
- Run at most one or two full builds at once; cap others with `-m:4`.
- Queue heavy builds and device runs; don't invent lease protocols between sessions.
- Never kill processes you didn't start.
- Before fanning out, check that no existing PR, branch, or session already covers the work.
39 changes: 21 additions & 18 deletions .github/skills/tests/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name: tests
description: >-
Runs, discovers, or recommends dotnet/android tests. Handles standalone tests
(plain dotnet test), full-build tests (local SDK required), and on-device
(dotnetup dotnet test), full-build tests (local Android workload required), and on-device
MTP/NUnit tests. Maps source files to relevant test suites. Trigger on test
execution requests, questions about available tests, or "which tests should I
run for this change?"
Expand All @@ -14,18 +14,21 @@ Consult `references/test-catalog.md` for the full mapping of test areas → asse

## Test categories

- **Standalone** — `dotnet test <project>.csproj`. No local SDK needed.
- **Full-build** — requires the local SDK at `bin/Debug/dotnet/dotnet` (or Release). Use `./dotnet-local.sh` (macOS/Linux) or `dotnet-local.cmd` (Windows).
- **Standalone** — `dotnetup dotnet test <project>.csproj`. Only the pinned shared SDK is needed, not a local Android build.
- **Full-build** — requires worktree-local Android packs and manifests. Use `./dotnet-local.sh` (macOS/Linux) or `dotnet-local.cmd` (Windows) with the shared SDK.

Check for the local SDK in the configuration needed by the tests:
```bash
CONFIGURATION=Debug # Set to Release for Release tests.
test -x "bin/${CONFIGURATION}/dotnet/dotnet"
```

**If the local SDK is missing, prepare and build it, then run the full-build tests.** On macOS/Linux, use `make prepare && make leeroy` (not `make all`); on Windows, use `build.cmd`. For Release tests on macOS/Linux, use `make prepare CONFIGURATION=Release && make leeroy CONFIGURATION=Release`. The presence of the `dotnet` executable only confirms provisioning, not that the SDK or test assemblies have been built. Rebuild after source changes so tests exercise the updated SDK. See `local-build` for per-project rebuilds and known issues, and `android-devices` for emulators.
Install the pinned SDK with `dotnetup sdk install` from the repository root.
For full-build tests, build `Microsoft.Android.slnx` with `dotnetup dotnet build`
first; rebuild after source changes. The wrappers report missing local workloads.
They default to Debug; export `CONFIGURATION=Release` for Release workloads and
also pass `-c Release` to build/test commands. The wrappers keep the repository
root's SDK pin while preserving the caller's `global.json` test-runner settings.
Forward SDK help with `dotnetup dotnet -- test --help`.

**Validate code changes locally before pushing.** Full SDK builds and relevant host/device tests are expected development work. Do not label them prohibitively slow, ask whether to skip them solely because of presumed duration, or rely on CI as the first validation. Start with focused tests while iterating and expand coverage as needed for the affected components. Never silently skip tests: if the user explicitly limits validation or an actual environment constraint blocks it, report the exact command, failure or missing prerequisite, and remaining unvalidated coverage. Include commands and outcomes in the handoff.
Validate locally before pushing: build missing prerequisites, run focused tests,
then expand coverage as needed. Do not skip required builds/device tests because
of presumed duration or use CI as a substitute. Report exact commands and outcomes,
including concrete blockers and remaining unvalidated coverage.

## Workflow

Expand Down Expand Up @@ -73,8 +76,8 @@ The `${TFM}` placeholder = `DotNetStableTargetFramework` from `Directory.Build.p

### Standalone
```bash
dotnet test <project>.csproj -v minimal
dotnet test <project>.csproj -v minimal --filter "Name~TestName"
dotnetup dotnet test <project>.csproj -v minimal
dotnetup dotnet test <project>.csproj -v minimal --filter "Name~TestName"
```

### Host-side MSBuild tests (full-build)
Expand All @@ -95,29 +98,29 @@ ADB_TARGET='-s emulator-5554' ./dotnet-local.sh test bin/TestDebug/MSBuildDevice
CI runs these assemblies with Microsoft Testing Platform, and splits them across jobs with
`build-tools/automation/scripts/RunSlicedTests.cs`:
```bash
./bin/Debug/dotnet/dotnet run build-tools/automation/scripts/RunSlicedTests.cs -- \
dotnetup dotnet run build-tools/automation/scripts/RunSlicedTests.cs -- \
--test-assembly bin/TestDebug/${TFM}/Xamarin.Android.Build.Tests.dll --results-directory bin/TestDebug/TestResults \
--filter "FullyQualifiedName~BuildTest2" --slice 1 --total-slices 4
```

### On-device runtime tests (native MSTest/MTP, full-build + device)

Build and install the APK first, then run `dotnet test` from the test project directory so the project-local `global.json` enables Microsoft Testing Platform:
Build and install the APK first, then run `dotnet-local test` from the test project directory so the project-local `global.json` enables Microsoft Testing Platform:
```bash
./dotnet-local.sh build -t:Install -c Debug tests/Mono.Android-Tests/Mono.Android-Tests/Mono.Android.NET-Tests.csproj
(
cd tests/Mono.Android-Tests/Mono.Android-Tests
../../../dotnet-local.sh test Mono.Android.NET-Tests.csproj --no-build -c Debug --report-trx --results-directory ../../../bin/TestDebug/TestResults
)
```
Results are `.trx` files under `bin/TestDebug/TestResults/`. Repeat any `-c` and `-p:` arguments on both the build/install and `dotnet test --no-build` commands. With several devices attached, add `-p:Device=<serial>` to both.
Results are `.trx` files under `bin/TestDebug/TestResults/`. Repeat any `-c` and `-p:` arguments on both the build/install and `dotnet-local test --no-build` commands. With several devices attached, add `-p:Device=<serial>` to both.

### Java.Interop tests
Tooling tests are standalone (`dotnet test` on `.csproj`). Core JNI interop tests
Tooling tests are standalone (`dotnetup dotnet test` on `.csproj`). Core JNI interop tests
live in `tests/Mono.Android-Tests/Java.Interop-Tests/` and run on Android as part
of `Mono.Android.NET-Tests.csproj`, using the on-device commands above.

To build the generator tooling and its tests using the main solution's filter:
```bash
dotnet build src/generator/generator.slnf -c Debug
dotnetup dotnet build src/generator/generator.slnf -c Debug
```
Loading