[net11.0][NativeAOT] Hook _PrepareTrimConfiguration to fix IL3050 on Android#35094
[net11.0][NativeAOT] Hook _PrepareTrimConfiguration to fix IL3050 on Android#35094
Conversation
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
|
🚀 Dogfood this PR with:
curl -fsSL https://github.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 35094Or
iex "& { $(irm https://github.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 35094" |
There was a problem hiding this comment.
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
_MauiPrepareForILLinkto run before_PrepareTrimConfiguration(instead ofPrepareForILLink) so feature switches are present when_TrimmerFeatureSettingsis computed.
| </Target> | ||
|
|
||
| <Target Name="_MauiPrepareForILLink" BeforeTargets="PrepareForILLink;_GenerateRuntimeConfigurationFilesInputCache;XamlC"> | ||
| <Target Name="_MauiPrepareForILLink" BeforeTargets="_PrepareTrimConfiguration;_GenerateRuntimeConfigurationFilesInputCache;XamlC"> |
There was a problem hiding this comment.
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).
| <Target Name="_MauiPrepareForILLink" BeforeTargets="_PrepareTrimConfiguration;_GenerateRuntimeConfigurationFilesInputCache;XamlC"> | |
| <Target Name="_MauiPrepareForILLink" BeforeTargets="PrepareForILLink;PrepareTrimConfiguration;_PrepareTrimConfiguration;_GenerateRuntimeConfigurationFilesInputCache;XamlC"> |
| @@ -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> | |||
|
|
|||
There was a problem hiding this comment.
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.
| <!-- | |
| 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. | |
| --> |
|
/azp run maui-pr-uitests, maui-pr-devicetests |
|
Azure Pipelines successfully started running 2 pipeline(s). |
|
|
jonathanpeppers
left a comment
There was a problem hiding this comment.
Looks OK, I have the same question as:
Note
This PR was created with assistance from AI.
Port of #35071 to the
net11.0branch.Summary
Add
_PrepareTrimConfigurationto_MauiPrepareForILLink'sBeforeTargetsso thatRuntimeHostConfigurationOptionitems (likeIsHybridWebViewSupported) are added before the runtime's internal target snapshots them into_TrimmerFeatureSettings.Problem
dotnet/runtime PR #124801 moved the
RuntimeHostConfigurationOption→_TrimmerFeatureSettingsconversion fromPrepareForILLinkinto an earlier internal target (_PrepareTrimConfiguration). MAUI's_MauiPrepareForILLinkhooksBeforeTargets="PrepareForILLink", which now fires after the snapshot. As a result, ILC never receives--featureflags for MAUI's feature switches on Android NativeAOT, causing spurious IL3050 warnings forHybridWebViewHandler.This is the branch (
net11.0, SDK11.0.100-preview.3.26203.107) where the bug manifests — the .NET 11 SDK has_PrepareTrimConfiguration.Fix
Remove
PrepareForILLinkfromBeforeTargets(redundant — it's a transitive dependent of_PrepareTrimConfiguration) and add_PrepareTrimConfigurationinstead. This ensures MAUI'sRuntimeHostConfigurationOptionitems 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 toBeforeTargets="PrepareTrimConfiguration".Workaround for dotnet/runtime#127017
cc @sbomer @simonrozsival