Repository navigation
[Xamarin.Android.Build.Tasks] Support MT in four transform tasks - #13243
Merged
Merged
Conversation
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
Contributor
There was a problem hiding this comment.
🔵 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
simonrozsival
approved these changes
Oct 27, 2026
2 of 3 tasks
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Allow four item/string tasks to run in-process during
-mtbuilds instead of using separate task-host processes:AppendCustomMetadataToItemGroup,RuntimeIdentifierToAbi,SplitProperty, andProcessRuntimePackLibraryDirectories.Each task has a direct
[MSBuildMultiThreadableTask]attribute and uses a newMultithreadedAndroidTaskbase. UnlikeAndroidTask, this base does not capture the process working directory. It passes the engine-suppliedTaskEnvironmentto 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.Analyzer18.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:falseand the locally built SDK:AppendCustomMetadataToItemGroupRuntimeIdentifierToAbiSplitPropertyProcessRuntimePackLibraryDirectoriesThese 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, MSBuild18.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, andVerify-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.binlogtoolconfirms 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.mdworkflow documentation, and in particular should include: