Skip to content

[NativeAOT] Hook _PrepareTrimConfiguration to fix IL3050 on Android#35071

Closed
sbomer wants to merge 1 commit intomainfrom
dev/sbomer/maui-il3050
Closed

[NativeAOT] Hook _PrepareTrimConfiguration to fix IL3050 on Android#35071
sbomer wants to merge 1 commit intomainfrom
dev/sbomer/maui-il3050

Conversation

@sbomer
Copy link
Copy Markdown
Member

@sbomer sbomer commented Apr 21, 2026

Note

This PR was created with assistance from AI.

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.

Fix

Add _PrepareTrimConfiguration to the BeforeTargets list of _MauiPrepareForILLink. This ensures MAUI's RuntimeHostConfigurationOption items are present when the snapshot runs.

This is a temporary workaround using the internal target name. The runtime fix (dotnet/runtime#127253) renames this to the public PrepareTrimConfiguration. Once that flows, this should be updated to BeforeTargets="PrepareTrimConfiguration;PrepareForILLink;...".

Verified

Tested with a MAUI Android NativeAOT app using the android-il3050 local build:

  • Before: --feature:Microsoft.Maui.RuntimeFeature.IsHybridWebViewSupported=false missing → IL3050
  • After: --feature flag present → IL3050 suppressed

Workaround for dotnet/runtime#127017

cc @sbomer @simonrozsival

Copilot AI review requested due to automatic review settings April 21, 2026 23:16
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 21, 2026

🚀 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://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 35071

Or

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

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
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 transitive MSBuild targets so MAUI’s RuntimeHostConfigurationOption feature switches are applied early enough for Android NativeAOT trimming to pick them up, avoiding spurious IL3050 warnings.

Changes:

  • Hook _MauiPrepareForILLink to run before the runtime’s earlier trim-configuration snapshot target (_PrepareTrimConfiguration).

</Target>

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

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

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

Consider adding the public target name PrepareTrimConfiguration to the BeforeTargets list as well (e.g., PrepareTrimConfiguration;_PrepareTrimConfiguration;...). This keeps the workaround working both before and after the runtime target rename (and is safe because MSBuild ignores non-existent targets).

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

Copilot uses AI. Check for mistakes.
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 just had one question.

</Target>

<Target Name="_MauiPrepareForILLink" BeforeTargets="PrepareForILLink;_GenerateRuntimeConfigurationFilesInputCache;XamlC">
<Target Name="_MauiPrepareForILLink" BeforeTargets="_PrepareTrimConfiguration;_GenerateRuntimeConfigurationFilesInputCache;XamlC">
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.

Are we OK to use a private target name, like _PrepareTrimConfiguration, any chance it would be renamed?

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.

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.

It could be renamed or modified - this is relying on an implementation detail. See #35163.

I considered making PrepareTrimConfiguration public in dotnet/runtime#127253 but I no longer think that's a good idea.

PureWeen pushed a commit that referenced this pull request Apr 27, 2026
…Android (#35094)

> [!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

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@PureWeen
Copy link
Copy Markdown
Member

@sbomer main is net10.0 only and will never bet net11.0 until we go GA with net11.0 and just merge the whole thing back into main

do we need this PR?

Without PR With PR Verdict
main (net10.0 SDK) ✅ AOT passes (60/60) ❌ AOT fails (4 IL3050) PR #35071 BREAKS main
net11.0 (net11.0 SDK) ❌ AOT fails (IL3050) ✅ AOT passes (18/18) PR #35094 FIXES net11.0

The same 1-line change (PrepareForILLink_PrepareTrimConfiguration) has opposite effects on the two branches because the SDK build pipeline ordering differs:

  • On main (net10.0 SDK): PrepareForILLink works correctly as the hook point. Changing to _PrepareTrimConfiguration means the feature switches never get set → IL3050 appears.
  • On net11.0 (net11.0 SDK): PrepareForILLink runs too late (due to runtime#124801 changes). _PrepareTrimConfiguration runs earlier → feature switches work → IL3050 gone.

Bottom line:

@sbomer
Copy link
Copy Markdown
Member Author

sbomer commented Apr 27, 2026

Cloing this since the fix is in net11.0 and main is net10.0. only.

@sbomer sbomer closed this Apr 27, 2026
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.

4 participants