Skip to content

[Xamarin.Android.Build.Tasks] Support MT in four transform tasks - #13243

Merged
simonrozsival merged 2 commits into
mainfrom
jonathanpeppers-four-task-mt-support
Oct 27, 2026
Merged

simonrozsival merged 2 commits into
mainfrom
jonathanpeppers-four-task-mt-support

Conversation

@jonathanpeppers

@jonathanpeppers jonathanpeppers commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Allow four item/string tasks to run in-process during -mt builds instead of using separate task-host processes: AppendCustomMetadataToItemGroup, RuntimeIdentifierToAbi, SplitProperty, and ProcessRuntimePackLibraryDirectories.

Each task has a direct [MSBuildMultiThreadableTask] attribute and uses a new MultithreadedAndroidTask base. Unlike AndroidTask, this base does not capture the process working directory. It passes the engine-supplied TaskEnvironment to exception logging so relative paths keep the existing file-lock diagnostics. Legacy task bases and product <UsingTask/> declarations are unchanged.

Update MSBuild packages to 18.9.6 and add Microsoft.Build.TaskAuthoring.Analyzer 18.13.0-1.26522.101 as a private build dependency. Add a metadata-only migration test, relative-path lock tests, and a Copilot rule requiring MT support for all new tasks.

MT measurements

Before/after a .NET 11 Android app rebuild, using -m -mt -nr:false and the locally built SDK:

Task Calls Before After
AppendCustomMetadataToItemGroup 4 52.2 ms 1.6 ms
RuntimeIdentifierToAbi 3 27.9 ms 1.1 ms
SplitProperty 1 8.3 ms 0.3 ms
ProcessRuntimePackLibraryDirectories 1 18.5 ms 0.7 ms
Total 9 107.0 ms 3.7 ms

These are summed task durations from the binlogs, not total build time. All nine calls move in-process; total out-of-process task calls drop from 102 to 93. App task messages remain 4486.

A 16-project task-only MT build changes from 499 ms to 109 ms, with out-of-process calls dropping from 80 to 0.

These are single baseline/final captures, not a repeated benchmark. Whole-app timings varied between captures, so this does not establish an end-to-end app build speedup.

Validation

Local SDK 11.0.100-rc.2.26504.105, MSBuild 18.12.0-1.26504.105, and matching .NET 11 RC2 reference/runtime, ILLink, and MonoTargets packs. The Android task DLLs were built from this branch.

  • .\dotnet-local.cmd build Microsoft.Android.slnx -t:BuildDotNet -c Release -nr:false -v:minimal -bl:<evidence>\reviewfix-sdk-build.binlog: passed, 92 existing warnings, zero errors.
  • dotnet test bin\TestRelease\net10.0\Xamarin.Android.Build.Tests.dll --filter FullyQualifiedName~MultiThreadedMigrationTests -v:minimal: passed, 1 test on both .NET 10 and .NET 11 hosts.
  • dotnet test bin\TestRelease\Microsoft.Android.Build.BaseTasks-Tests.dll --filter "FullyQualifiedName~MultithreadedAndroidTaskTests|FullyQualifiedName~AndroidToolTaskTests.TestRegister|FullyQualifiedName~LockCheckTests" -v:minimal: passed, 19 tests on each host. Removing project-relative resolution makes both new relative-path cases fail.
  • Capture.ps1 -Prefix reviewfix, Check-Locks.ps1, and Verify-Evidence.ps1: passed ordinary and strict MT app/task fixtures with -warnaserror:MSB4286,MSB4287,MSB4288. Outputs, metadata, expected errors, and app DLL bytes match the baseline. All four tasks run in-process. File-lock details are retained across 16 project directories. binlogtool confirms local task/compiler paths and no leaked strict-mode sentinel paths.

The .NET 11 source build used temporary dependency pins, ARM64/x64 native ABIs, and a workload-manifest adjustment because main pins .NET 12-alpha dependencies. Those local adjustments are not in this PR.

Source issue: N/A.


Pull Request
title and
description
should follow the
commit-messages.md workflow documentation, and in particular should include:

  • Useful description of why the change is necessary.
  • Links to issues fixed
  • Unit tests

MSBuild runs unmarked tasks in separate task-host processes during
multithreaded builds.  Opt in the four item/string transforms with direct
MSBuildMultiThreadableTask attributes and use the independent
Microsoft.Android.Build.Tasks.MultithreadedAndroidTask base.

Avoid the legacy base constructor's process working-directory capture.
Pass the engine-supplied TaskEnvironment through exception logging so
relative paths retain file-lock diagnostics without process-state access.
Keep legacy task bases and their logging behavior unchanged.

Use MSBuild 18.9.6 APIs and enable the private official task-authoring
analyzer.  Add metadata-only migration checks that work on .NET 10 while
inspecting the shipped .NET 11 task assembly, plus base behavior tests.

Validate the locally built .NET 11 SDK in ordinary and strict MT modes.
All nine affected app task calls run in-process, with unchanged outputs.
Check concurrent project paths, file-lock details and expected errors.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 13592080-ad03-4e65-b6f3-d0b33011c60b
Copilot AI balanced review requested due to automatic review settings October 22, 2026 23:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Cross-project isolation needs final human verification, particularly project-relative lock diagnostics without checked-in regression coverage.

1 open issue
What changed in this PR

This PR opts four .NET for Android transform tasks into in-process execution during MSBuild multithreaded builds, avoiding task-host isolation without changing their transformation logic.

Changes:

  • Adds an independent multithreaded task base and project-scoped exception-path handling.
  • Updates MSBuild dependencies and enables task-authoring safety diagnostics.
  • Adds migration and diagnostic tests, plus guidance on migration and analyzer limits.
File Description
tests/​Microsoft.Android.Build.BaseTasks-Tests/​MultithreadedAndroidTaskTests.cs Tests task results and exception diagnostics.
src/​Xamarin.Android.Build.Tasks/​Tests/​Xamarin.Android.Build.Tests/​Tasks/​MultiThreadedMigrationTests.cs Checks direct task markers and rejects unsafe legacy bases.
src/​Xamarin.Android.Build.Tasks/​Tasks/​SplitProperty.cs Opts the property transform into multithreaded execution.
src/​Xamarin.Android.Build.Tasks/​Tasks/​RuntimeIdentifierToAbi.cs Opts the runtime-identifier transform into multithreaded execution.
src/​Xamarin.Android.Build.Tasks/​Tasks/​ProcessRuntimePackLibraryDirectories.cs Opts runtime-pack item processing into multithreaded execution.
src/​Xamarin.Android.Build.Tasks/​Tasks/​AppendCustomMetadataToItemGroup.cs Opts metadata transformation into multithreaded execution.
src/​Microsoft.Android.Build.Tasks/​Microsoft.Android.Build.Tasks.csproj Adds the private task-authoring analyzer.
src/​Microsoft.Android.Build.BaseTasks/​UnhandledExceptionLogger.cs Resolves diagnostic paths using the supplied task environment.
src/​Microsoft.Android.Build.BaseTasks/​MultithreadedAndroidTask.cs Adds a task base without process-directory capture.
src/​Microsoft.Android.Build.BaseTasks/​MSBuildReferences.projitems Updates shared dependencies and adds the analyzer.
NuGet.config Adds the analyzer package feed.
Documentation/​guides/​MSBuildBestPractices.md Documents multithreaded migration and validation.
Directory.Build.props Defines the analyzer version.
.editorconfig Treats selected task-safety diagnostics as errors.

Review effort: Balanced

Extend the existing file-lock test with relative exception paths and an
explicit TaskEnvironment whose directory differs from the process CWD.
Keep the absolute-path fallback cases and check both I/O and access-denied
errors.  Removing project-relative resolution now fails the new cases
instead of leaving the checked-in tests green.

Require all new MSBuild tasks to support multithreaded execution in the
Copilot instructions.  Document direct attributes, safe task bases, and
project-scoped environment access rather than process-state dependencies.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 13592080-ad03-4e65-b6f3-d0b33011c60b
@jonathanpeppers jonathanpeppers added the ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable). label Oct 23, 2026
@simonrozsival
simonrozsival merged commit 4ffbe4d into main Oct 27, 2026
41 checks passed
@simonrozsival
simonrozsival deleted the jonathanpeppers-four-task-mt-support branch October 27, 2026 07:35
jonathanpeppers added a commit that referenced this pull request Nov 24, 2026
Keep ProcessRuntimePackLibraryDirectories deleted because the release branch replaced it with MSBuild item operations.

Co-authored-by: Copilot App <[email protected]>
jonathanpeppers added a commit that referenced this pull request Nov 24, 2026
Include the latest release-branch changes before updating the backport pull request.

Co-authored-by: Copilot App <[email protected]>
jonathanpeppers added a commit that referenced this pull request Nov 24, 2026
Allow AppendCustomMetadataToItemGroup, RuntimeIdentifierToAbi, and ProcessRuntimePackLibraryDirectories to run in-process in multithreaded MSBuild. Keep the release branch XML replacement for SplitProperty from #13689.

Bring over the MT task base and exception path handling, MSBuild 18.9.6, task authoring analyzer, documentation, and tests. Preserve the release branch dependency versions and references.

(cherry picked from commit 4ffbe4d)

Co-authored-by: Copilot App <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants