Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Feb 3, 2026

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 <787361+sbomer@users.noreply.github.com>
- Remove placeholder issue number from comment
- Remove trailing whitespace

Co-authored-by: sbomer <787361+sbomer@users.noreply.github.com>
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MSB4096 with user-defined TrimmerRootAssembly

3 participants