Skip to content

Move CheckForObsoletePreserveAttribute into PostTrimmingPipeline - #11009

Merged
jonathanpeppers merged 2 commits into
mainfrom
copilot/move-check-for-obsolete-preserve-attribute
Mar 30, 2026
Merged

Move CheckForObsoletePreserveAttribute into PostTrimmingPipeline#11009
jonathanpeppers merged 2 commits into
mainfrom
copilot/move-check-for-obsolete-preserve-attribute

Conversation

Copilot AI commented Mar 24, 2026

Copy link
Copy Markdown
Contributor

CheckForObsoletePreserveAttribute runs as a standalone MSBuild task on every incremental build, costing ~120ms to open and scan every user assembly with PEReader. This is unnecessary work since PostTrimmingPipeline already loads all assemblies via Mono.Cecil.

Changes

  • New CheckForObsoletePreserveAttributeStep — implements IAssemblyModifierPipelineStep, checks for Android.Runtime.PreserveAttribute type references using the already-loaded AssemblyDefinition (zero additional I/O)
  • Added step to PostTrimmingPipeline — runs before StripEmbeddedLibrariesStep, emits the same IL6001 warning
  • Removed standalone infrastructure — deleted CheckForObsoletePreserveAttribute.cs task, its UsingTask declaration, and the _CheckForObsoletePreserveAttribute target from Microsoft.Android.Sdk.AssemblyResolution.targets

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
Comment thread src/Xamarin.Android.Build.Tasks/Tasks/PostTrimmingPipeline.cs
…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
Copilot AI requested a review from jonathanpeppers March 24, 2026 21:08
@simonrozsival
simonrozsival marked this pull request as ready for review March 26, 2026 16:43
@simonrozsival
simonrozsival self-requested a review as a code owner March 26, 2026 16:43
Copilot AI review requested due to automatic review settings March 26, 2026 16:43

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.

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 CheckForObsoletePreserveAttributeStep implementing IAssemblyModifierPipelineStep to emit IL6001 without extra I/O.
  • Registered the new step in PostTrimmingPipeline so it runs alongside other post-trim assembly modifications.
  • Removed the standalone CheckForObsoletePreserveAttribute MSBuild task and its _CheckForObsoletePreserveAttribute target 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.

Comment thread src/Xamarin.Android.Build.Tasks/Tasks/PostTrimmingPipeline.cs
@jonathanpeppers
jonathanpeppers merged commit 323f58b into main Mar 30, 2026
10 checks passed
@jonathanpeppers
jonathanpeppers deleted the copilot/move-check-for-obsolete-preserve-attribute branch March 30, 2026 13:36
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 30, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants