Move CheckForObsoletePreserveAttribute into PostTrimmingPipeline - #11009
Merged
jonathanpeppers merged 2 commits intoMar 30, 2026
Merged
Conversation
Previously, CheckForObsoletePreserveAttribute ran as a separate MSBuild task on every incremental build (AfterTargets="_PrepareAssemblies"), taking ~120ms to open and read every user assembly with PEReader. Now the check runs as a step in PostTrimmingPipeline, where assemblies are already loaded by Mono.Cecil. This eliminates the overhead of separately opening each assembly file, and the check only runs when trimming is enabled. Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com> Agent-Logs-Url: https://github.com/dotnet/android/sessions/34cf49e8-922e-4ad8-b7ea-c598fcf71b63
Copilot created this pull request from a session on behalf of
jonathanpeppers
March 24, 2026 19:34
View session
…d missing using The Linker\** directory is excluded from compilation by default, so files must be explicitly listed. Also add the missing Microsoft.Android.Build.Tasks using directive for the LogCodedWarning extension method. Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com> Agent-Logs-Url: https://github.com/dotnet/android/sessions/0d36b884-8972-4ef3-b842-8834afd6a7af
simonrozsival
approved these changes
Mar 26, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR aims to remove the incremental-build cost of scanning assemblies for Android.Runtime.PreserveAttribute references by moving the check into the existing post-trimming pipeline, reusing already-loaded Mono.Cecil assemblies.
Changes:
- Added a new
CheckForObsoletePreserveAttributeStepimplementingIAssemblyModifierPipelineStepto emitIL6001without extra I/O. - Registered the new step in
PostTrimmingPipelineso it runs alongside other post-trim assembly modifications. - Removed the standalone
CheckForObsoletePreserveAttributeMSBuild task and its_CheckForObsoletePreserveAttributetarget wiring.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj | Includes the new linker step source file in the explicit Linker compile list. |
| src/Xamarin.Android.Build.Tasks/Tasks/PostTrimmingPipeline.cs | Adds the new warning step into the post-trimming step list. |
| src/Xamarin.Android.Build.Tasks/Tasks/CheckForObsoletePreserveAttribute.cs | Removes the standalone PEReader-based task implementation. |
| src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.AssemblyResolution.targets | Removes the UsingTask and target that ran the warning task after _PrepareAssemblies. |
| src/Xamarin.Android.Build.Tasks/Linker/MonoDroid.Tuner/CheckForObsoletePreserveAttributeStep.cs | New Cecil-based pipeline step that detects PreserveAttribute type references and logs IL6001. |
jonathanpeppers
approved these changes
Mar 30, 2026
jonathanpeppers
deleted the
copilot/move-check-for-obsolete-preserve-attribute
branch
March 30, 2026 13:36
This was referenced Mar 30, 2026
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
CheckForObsoletePreserveAttributeruns as a standalone MSBuild task on every incremental build, costing ~120ms to open and scan every user assembly withPEReader. This is unnecessary work sincePostTrimmingPipelinealready loads all assemblies via Mono.Cecil.Changes
CheckForObsoletePreserveAttributeStep— implementsIAssemblyModifierPipelineStep, checks forAndroid.Runtime.PreserveAttributetype references using the already-loadedAssemblyDefinition(zero additional I/O)PostTrimmingPipeline— runs beforeStripEmbeddedLibrariesStep, emits the sameIL6001warningCheckForObsoletePreserveAttribute.cstask, itsUsingTaskdeclaration, and the_CheckForObsoletePreserveAttributetarget fromMicrosoft.Android.Sdk.AssemblyResolution.targets