Skip to content

[build] Avoid staging unchanged framework assemblies - #12448

Merged
jonathanpeppers merged 3 commits into
mainfrom
dev/simonrozsival/avoid-framework-assembly-staging
Aug 21, 2026
Merged

jonathanpeppers merged 3 commits into
mainfrom
dev/simonrozsival/avoid-framework-assembly-staging

Conversation

@simonrozsival

Copy link
Copy Markdown
Member

Summary

  • identify framework assemblies that cannot contain Android types during ProcessAssemblies
  • skip Cecil processing and project-local DLL copies for those assemblies in Debug/no-shrink builds
  • package unchanged framework assemblies directly from their runtime-pack locations
  • retain project-local zero-byte scan markers for JCW and typemap consumers
  • continue fully processing Android framework assemblies such as Mono.Android and Java.Interop

I/O impact

For a clean MAUI Debug LLVM-IR build on arm64, the assembly staging directory changed from approximately 327 DLLs / 160.6 MiB to 145 DLLs / 93.3 MiB. This avoids 182 DLL copies and about 67 MiB of project-local staging writes.

Validation

  • built Xamarin.Android.Build.Tasks.csproj
  • clean and no-op MAUI LLVM-IR builds
  • confirmed Microsoft.CSharp.dll is packaged from the runtime pack and represented locally by a scan marker
  • confirmed Mono.Android.dll is still staged, scanned, and present in the generated native typemap
  • confirmed LinkAssembliesNoShrink is skipped on a no-op build
  • passed MultiTfmTransitiveReference CoreCLR regression coverage

Related: #10958

Package non-Android framework assemblies directly from runtime packs instead of opening and copying them into project intermediates. Keep project-local zero-byte scan markers for downstream typemap and JCW consumers.

Co-authored-by: Copilot <[email protected]>

Copilot-Session: 6469f820-c19a-4450-8bb9-de70387d899c
Copilot AI lite review requested due to automatic review settings August 19, 2026 15:35
@simonrozsival

Copy link
Copy Markdown
Member Author

/review

@github-actions

github-actions Bot commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Security scanning failed for Android PR Reviewer. Review the logs for details.

Generated by Android PR Reviewer for #12448

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 optimizes the .NET for Android build pipeline by identifying framework/runtime-pack assemblies that cannot contain Android types and avoiding unnecessary staging/copying and Cecil-based processing for those assemblies in Debug/no-shrink scenarios, while preserving the scan “sidecar” contract via zero-byte markers.

Changes:

  • Introduces %(AndroidSkipAssemblyModification)=True metadata for non-Android framework/runtime-pack assemblies during ProcessAssemblies.
  • Updates _LinkAssembliesNoShrink incrementalism and processing to emit a single zero-byte scan marker (.scan.empty) instead of staging the DLL for those assemblies.
  • Updates JCW and typemap consumers to resolve sidecar paths from item metadata when provided (falling back to the historical “next to assembly” convention otherwise), enabling the marker-based flow.
Show a summary per file
File Description
src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets Splits resolved assemblies/symbols into “link-no-shrink” vs “package without modification” groups and updates _LinkAssembliesNoShrink Outputs to include marker files for skipped assemblies.
src/Xamarin.Android.Build.Tasks/Utilities/TypeMapObjectsXmlFile.cs Adds ITaskItem overload to resolve typemap XML path from item metadata (supporting marker files).
src/Xamarin.Android.Build.Tasks/Utilities/TypeMapGenerator.cs Switches typemap lookup to the new ITaskItem-aware path resolver.
src/Xamarin.Android.Build.Tasks/Utilities/JavaObjectsXmlFile.cs Adds ITaskItem overload to resolve JLO XML path from item metadata (supporting marker files).
src/Xamarin.Android.Build.Tasks/Tasks/ProcessAssemblies.cs Sets FrameworkAssembly, HasMonoAndroidReference, and new AndroidSkipAssemblyModification metadata (including for symbol items).
src/Xamarin.Android.Build.Tasks/Tasks/LinkAssembliesNoShrink.cs Skips the pipeline for marked assemblies and writes a zero-byte .scan.empty marker file.
src/Xamarin.Android.Build.Tasks/Tasks/GenerateJavaCallableWrappers.cs Uses the ITaskItem-aware JLO path resolver so marker files work.
src/Xamarin.Android.Build.Tasks/Tasks/GenerateACWMap.cs Uses the ITaskItem-aware JLO path resolver so marker files work.
src/Xamarin.Android.Build.Tasks/Tasks/AssemblyModifierPipeline.cs Adds an overridable fast-path hook (TryProcessWithoutPipeline) used by LinkAssembliesNoShrink.
src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.AssemblyResolution.targets Updates _PrepareAssemblies to stage only modified assemblies while keeping non-Android framework assemblies sourced from runtime-pack locations.

Review details

  • Files reviewed: 10/10 changed files
  • Comments generated: 0
  • Review effort level: Lite

Keep conditional output metadata on the original ResolvedAssemblies items so MSBuild can correlate inputs and outputs during partial builds.

Co-authored-by: Copilot <[email protected]>

Copilot-Session: 986b59ba-93bf-46dc-a6c0-4f01dd7e2b3f
@simonrozsival

Copy link
Copy Markdown
Member Author

/review

@github-actions

github-actions Bot commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

✅ Android PR Reviewer completed successfully!

Generated by Android PR Reviewer for #12448

@github-actions github-actions Bot 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 Changes — 0 errors, 1 warning, 0 suggestions.

The runtime-pack optimization is coherently wired through assembly classification, marker creation, MSBuild item transforms, and both scanner consumers. CI build 1560590 and all reported checks are green. The remaining concern is automated regression coverage for the new packaging/marker/no-op path; the existing test cited in the PR does not exercise that branch.

Generated by Android PR Reviewer for #12448 · gpt56 · 254.2 AIC · ⌖ 8.93 AIC · ⊞ 25.7K
Comment /review to run again

Verify runtime-pack packaging, shared scan markers, Android framework staging, and no-op incremental behavior.

Co-authored-by: Copilot <[email protected]>
@simonrozsival

Copy link
Copy Markdown
Member Author

/review

@github-actions

github-actions Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

✅ Android PR Reviewer completed successfully!

Generated by Android PR Reviewer for #12448

@github-actions github-actions Bot 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 Changes

Findings: 0 errors · 1 warning · 0 suggestions

The item-group split and zero-byte sidecar marker are coherent, and the new test verifies direct runtime-pack packaging plus no-op incremental behavior for CoreCLR. The remaining gap is coverage of MonoVM's distinct discrete-assembly/PDB packaging path.

CI build 1561960 is still in progress; CLA and the completed Android Tools Tests Mac check are green, with no failures reported so far.

Generated by Android PR Reviewer for #12448 · gpt56 · 229.3 AIC · ⌖ 8.86 AIC · ⊞ 25.7K
Comment /review to run again

EmbedAssembliesIntoApk = true,
Imports = { captureFrameworkAssemblies },
};
proj.SetRuntime (AndroidRuntime.CoreCLR);

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.

🤖 ⚠️ Testing — This regression test only exercises CoreCLR's mandatory assembly-store path, but the target changes also affect MonoVM debug builds, where assembly stores are disabled and WrapAssembliesAsSharedLibraries packages each DLL/PDB directly. Please parameterize this coverage for MonoVM (including the discrete assembly and symbol archive entries) so the new runtime-pack source paths are verified on both packaging paths.

Rule: Test changed behavior across configurations

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

MonoVM Android builds are no longer supported on .NET 11. Attempting to parameterize this test for AndroidRuntime.MonoVM fails with NETSDK1242 before reaching _LinkAssembliesNoShrink or the discrete packaging path. MonoVM build-test variants were intentionally removed in d115ab9cd and 72788a388 for this reason. Also, the runtime pack does not ship Microsoft.CSharp.pdb, so there is no skipped-framework symbol entry to assert. The existing CoreCLR case covers the supported Debug/no-shrink path affected by this PR.

@jonathanpeppers
jonathanpeppers merged commit f96cd7f into main Aug 21, 2026
44 checks passed
@jonathanpeppers
jonathanpeppers deleted the dev/simonrozsival/avoid-framework-assembly-staging branch August 21, 2026 13:01
@jonathanpeppers

Copy link
Copy Markdown
Member

I think this change breaks the debugger in VS Code:

'hotweloadtester.dll' (CoreCLR: DefaultDomain): Failed to load metadata for 'System.Private.CoreLib', possibly because the process is corrupt.
A fatal error has occurred loading the metadata for 'System.Private.CoreLib' and debugging needs to be terminated. Unknown Error: 0x80131c35

It looks in the obj/Debug/assets folder and finds scan.empty files, copilot analysis:

It means the debugger connected successfully, but then failed with CORDBG_E_MISSING_METADATA while loading .NET 11’s System.Private.CoreLib.

The app is likely not corrupt. The Android build now leaves only System.Private.CoreLib.scan.empty in the debugger assets directory while the real DLL remains in the runtime pack. VSDBG is being given the incomplete assets path, so debugging terminates after attach. This is separate from dotnet watch; the normal launch reproduces it too.

Should we revert this for now?

@simonrozsival

Copy link
Copy Markdown
Member Author

Should we revert this for now?

yeah, I'll open a PR.

jonathanpeppers pushed a commit that referenced this pull request Sep 1, 2026
## Summary

- revert #12448
- restore project-local staging for unchanged framework assemblies
- preserve the satellite assembly scan-marker fix from #12496

## Validation

- `dotnet build src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj --no-restore --nologo`

Co-authored-by: Copilot App <[email protected]>
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 1, 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.

3 participants