Skip to content

Fix MSB4096 error with user-defined TrimmerRootAssembly items lacking RootMode metadata - #10759

Merged
jonathanpeppers merged 5 commits into
mainfrom
copilot/fix-msb4096-trimmer-root-assembly
Feb 4, 2026
Merged

jonathanpeppers merged 5 commits into
mainfrom
copilot/fix-msb4096-trimmer-root-assembly

Conversation

Copilot AI commented Feb 3, 2026 •

Copy link
Copy Markdown
Contributor

The _FixRootAssembly target fails with MSB4096 when users add TrimmerRootAssembly items without RootMode metadata. The unqualified %(RootMode) reference triggers MSBuild item batching, which requires all items to define the metadata.

Changes

  • Microsoft.Android.Sdk.ILLink.targets: Qualify metadata reference as %(TrimmerRootAssembly.RootMode)
    • Items without RootMode are now skipped (condition evaluates to '' == 'EntryPoint') instead of causing batching errors
  • BuildTest.cs: Add test for TrimmerRootAssembly items without RootMode metadata
- <TrimmerRootAssembly Update="@(TrimmerRootAssembly)" Condition=" '%(RootMode)' == 'EntryPoint' " RootMode="All" />
+ <TrimmerRootAssembly Update="@(TrimmerRootAssembly)" Condition=" '%(TrimmerRootAssembly.RootMode)' == 'EntryPoint' " RootMode="All" />

User projects can now safely add trimmer root assemblies without metadata:

<ItemGroup>
  <TrimmerRootAssembly Include="Microsoft.Maui" />
  <TrimmerRootAssembly Include="Microsoft.Maui.Controls" />
</ItemGroup>
Original prompt

This section details on the original issue you should resolve

<issue_title>MSB4096 with user-defined TrimmerRootAssembly</issue_title>
<issue_description>### Summary

The _FixRootAssembly target in Microsoft.Android.Sdk.ILLink.targets uses %(RootMode) without fully qualifying it as %(TrimmerRootAssembly.RootMode). This causes MSB4096 when user-defined TrimmerRootAssembly items don't have the RootMode metadata.

Repro

Create a MAUI app with TrimmerRootAssembly items that don't specify RootMode:

<ItemGroup>
  <TrimmerRootAssembly Include="Microsoft.Maui" />
  <TrimmerRootAssembly Include="Microsoft.Maui.Controls" />
</ItemGroup>

Error

error MSB4096: The item "Microsoft.Maui" in item list "TrimmerRootAssembly" does not define a value for metadata "RootMode". In order to use this metadata, either qualify it by specifying %(TrimmerRootAssembly.RootMode), or ensure that all items in this list define a value for this metadata.

In Microsoft.Android.Sdk.ILLink.targets:

<Target Name="_FixRootAssembly" AfterTargets="PrepareForILLink">
  <ItemGroup>
    <TrimmerRootAssembly Update="@(TrimmerRootAssembly)" Condition=" '%(RootMode)' == 'EntryPoint' " RootMode="All" />
  </ItemGroup>
</Target>

The condition uses %(RootMode) which triggers MSBuild item batching. When batching, MSBuild requires all items to have the metadata defined.

Related: dotnet/runtime#123972 (comment)</issue_description>

<agent_instructions>Reproduce the failure. Then try changing the condition to reference TrimmerRootAssembly.RootMode instead of RootMode, which should allow it to filter for items that have metadata (without requiring every TrimmerRootAssembly to have RootMode metadata).</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits February 3, 2026 23:05
Change %(RootMode) to %(TrimmerRootAssembly.RootMode) in _FixRootAssembly target to avoid requiring all TrimmerRootAssembly items to have RootMode metadata. Add test case to verify the fix.

Co-authored-by: sbomer <[email protected]>
- Remove placeholder issue number from comment
- Remove trailing whitespace

Co-authored-by: sbomer <[email protected]>
Copilot AI changed the title [WIP] Fix MSB4096 error with user-defined TrimmerRootAssembly Fix MSB4096 error with user-defined TrimmerRootAssembly items lacking RootMode metadata Feb 3, 2026
Copilot AI requested a review from sbomer February 3, 2026 23:11
@jonathanpeppers
jonathanpeppers marked this pull request as ready for review February 4, 2026 15:06
Copilot AI review requested due to automatic review settings February 4, 2026 15:06

@jonathanpeppers jonathanpeppers left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

New test passes:

Image

Build_From_Clean_DontIncludeRestore is only failure, and we've removed this flaky test in main.

@jonathanpeppers
jonathanpeppers merged commit e87001a into main Feb 4, 2026
5 of 9 checks passed
@jonathanpeppers
jonathanpeppers deleted the copilot/fix-msb4096-trimmer-root-assembly branch February 4, 2026 15:09

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 fixes an MSB4096 error that occurs when users add TrimmerRootAssembly items without the RootMode metadata. The issue was caused by an unqualified metadata reference in the _FixRootAssembly target, which triggered MSBuild item batching that requires all items to have the metadata defined.

Changes:

  • Qualified the metadata reference from %(RootMode) to %(TrimmerRootAssembly.RootMode) in the condition
  • Added a test case to verify that user-defined TrimmerRootAssembly items without RootMode metadata work correctly

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.ILLink.targets Fixed metadata reference in _FixRootAssembly target to use qualified form, preventing MSB4096 batching error
src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs Added test to verify user-defined TrimmerRootAssembly items without RootMode metadata don't cause build failures

@github-actions github-actions Bot locked and limited conversation to collaborators Mar 7, 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.

MSB4096 with user-defined TrimmerRootAssembly

4 participants