Skip to content

[net11.0][NativeAOT] Hook _PrepareTrimConfiguration to fix IL3050 on Android#35094

Merged
PureWeen merged 1 commit intonet11.0from
dev/sbomer/maui-il3050-net11
Apr 27, 2026
Merged

[net11.0][NativeAOT] Hook _PrepareTrimConfiguration to fix IL3050 on Android#35094
PureWeen merged 1 commit intonet11.0from
dev/sbomer/maui-il3050-net11

Conversation

@sbomer
Copy link
Copy Markdown
Member

@sbomer sbomer commented Apr 22, 2026

Note

This PR was created with assistance from AI.

Port of #35071 to the net11.0 branch.

Summary

Add _PrepareTrimConfiguration to _MauiPrepareForILLink's BeforeTargets so that RuntimeHostConfigurationOption items (like IsHybridWebViewSupported) are added before the runtime's internal target snapshots them into _TrimmerFeatureSettings.

Problem

dotnet/runtime PR #124801 moved the RuntimeHostConfigurationOption_TrimmerFeatureSettings conversion from PrepareForILLink into an earlier internal target (_PrepareTrimConfiguration). MAUI's _MauiPrepareForILLink hooks BeforeTargets="PrepareForILLink", which now fires after the snapshot. As a result, ILC never receives --feature flags for MAUI's feature switches on Android NativeAOT, causing spurious IL3050 warnings for HybridWebViewHandler.

This is the branch (net11.0, SDK 11.0.100-preview.3.26203.107) where the bug manifests — the .NET 11 SDK has _PrepareTrimConfiguration.

Fix

Remove PrepareForILLink from BeforeTargets (redundant — it's a transitive dependent of _PrepareTrimConfiguration) and add _PrepareTrimConfiguration instead. This ensures MAUI's RuntimeHostConfigurationOption items are present when the snapshot runs.

Temporary workaround using the internal target name. The runtime fix (dotnet/runtime#127253) renames this to the public PrepareTrimConfiguration. Once that flows, update to BeforeTargets="PrepareTrimConfiguration".

Workaround for dotnet/runtime#127017

cc @sbomer @simonrozsival

Add _PrepareTrimConfiguration to _MauiPrepareForILLink's BeforeTargets
so that RuntimeHostConfigurationOption items (like IsHybridWebViewSupported)
are added before the runtime's _PrepareTrimConfiguration target snapshots
them into _TrimmerFeatureSettings. Without this, ILC never receives
--feature flags for MAUI's feature switches on Android where
RunILLink=true, causing spurious IL3050 warnings.

This is a temporary workaround using the internal target name. Once
dotnet/runtime ships the fix (renaming to public PrepareTrimConfiguration),
this should be updated to BeforeTargets="PrepareTrimConfiguration".

Workaround for dotnet/runtime#127017

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Assisted-by: Claude:claude-opus-4.6-1m
Copilot AI review requested due to automatic review settings April 22, 2026 18:12
@github-actions
Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://github.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 35094

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://github.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 35094"

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates MAUI’s build-transitive targets to ensure RuntimeHostConfigurationOption feature switches are applied early enough for Android NativeAOT trimming, avoiding spurious IL3050 warnings after dotnet/runtime moved the snapshotting logic earlier in the target graph.

Changes:

  • Retarget _MauiPrepareForILLink to run before _PrepareTrimConfiguration (instead of PrepareForILLink) so feature switches are present when _TrimmerFeatureSettings is computed.

</Target>

<Target Name="_MauiPrepareForILLink" BeforeTargets="PrepareForILLink;_GenerateRuntimeConfigurationFilesInputCache;XamlC">
<Target Name="_MauiPrepareForILLink" BeforeTargets="_PrepareTrimConfiguration;_GenerateRuntimeConfigurationFilesInputCache;XamlC">
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

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

Dropping PrepareForILLink from BeforeTargets makes this target rely on _PrepareTrimConfiguration being present/invoked to ensure the RuntimeHostConfigurationOption items are set before trimming. To keep the hook resilient across SDK/runtime target graph changes (and align with the original fix strategy), keep PrepareForILLink in the list as a fallback (and optionally add the future public PrepareTrimConfiguration name as well).

Suggested change
<Target Name="_MauiPrepareForILLink" BeforeTargets="_PrepareTrimConfiguration;_GenerateRuntimeConfigurationFilesInputCache;XamlC">
<Target Name="_MauiPrepareForILLink" BeforeTargets="PrepareForILLink;PrepareTrimConfiguration;_PrepareTrimConfiguration;_GenerateRuntimeConfigurationFilesInputCache;XamlC">

Copilot uses AI. Check for mistakes.
@@ -306,7 +306,7 @@
Text="The %24(TargetFrameworkVersion) for $(ProjectName) ($(TargetFrameworkVersion)) is less than the minimum required %24(TargetFrameworkVersion) for Microsoft.Maui ($(MinTargetFrameworkVersionForMaui)). You need to increase the %24(TargetFrameworkVersion) for $(ProjectName)." />
</Target>

Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

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

This target now hooks an internal SDK target name (_PrepareTrimConfiguration) as a workaround. Please add a short XML comment on/above this target explaining the runtime issue/workaround and that it should be switched to PrepareTrimConfiguration once available, so future maintainers don’t remove or “clean up” the underscore target reference.

Suggested change
<!--
Intentionally hook the internal SDK target `_PrepareTrimConfiguration` as a workaround for
the current runtime/SDK trimming issue. Do not remove or "clean up" the underscore target
reference; switch this to `PrepareTrimConfiguration` once that public target is available.
-->

Copilot uses AI. Check for mistakes.
@PureWeen
Copy link
Copy Markdown
Member

/azp run maui-pr-uitests, maui-pr-devicetests

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 2 pipeline(s).

@MauiBot
Copy link
Copy Markdown
Collaborator

MauiBot commented Apr 24, 2026

⚠️ Merge Conflict Detected — This PR has merge conflicts with its target branch. Please rebase onto the target branch and resolve the conflicts.

Copy link
Copy Markdown
Member

@jonathanpeppers jonathanpeppers left a comment

Choose a reason for hiding this comment

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

Looks OK, I have the same question as:

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.

5 participants