-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Trimming] Add a feature flag to disable XAML loading at runtime (#19310
) * Add feature flag * Add rudimentary docs for feature flags * Add feature flag guards and attributes with warnings * TMP: Add TODO comment to resolve issue with XamlC calling SetAndLoadSource * Move feature flags to Core * Fix typos * List affected APIs in the docs * Add summary comment for RuntimeFeature * Improve ResourceDictionary.SetAndLoadSource * Fix comment * Rename feature switch property and name * Remove comment * Revisit ResourceDictionary * Remove annotations from ResourcesLoader * Remove fixed warnings from tests * Remove unnecessary changes * Update docs/design/FeatureSwitches.md Co-authored-by: Rolf Bjarne Kvinge <rolf@xamarin.com> * Move feature switch setup code to Controls targets file * Remove ILC System.Enum.GetValues warning * Remove unnecessary Debug fallback * Suppress trimming warnings in source-generated code * Update docs/design/FeatureSwitches.md Co-authored-by: MartyIX <203266+MartyIX@users.noreply.github.com> --------- Co-authored-by: Rolf Bjarne Kvinge <rolf@xamarin.com> Co-authored-by: MartyIX <203266+MartyIX@users.noreply.github.com>
- Loading branch information
1 parent
6c50c5f
commit a1096cc
Showing
12 changed files
with
98 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Feature Switches | ||
|
||
Certain features of MAUI can be enabled or disabled using feature switches. The easiest way to control the features is by putting the corresponding MSBuild property into the app's project file. Disabling unnecessary features can help reducing the app size when combined with the [`full` trimming mode](https://learn.microsoft.com/en-us/dotnet/core/deploying/trimming/trimming-options). | ||
|
||
| MSBuild Property Name | AppContext Setting | Description | | ||
|-|-|-| | ||
| MauiXamlRuntimeParsingSupport | Microsoft.Maui.RuntimeFeature.IsXamlRuntimeParsingSupported | When disabled, all XAML loading at runtime will throw an exception. This will affect usage of APIs such as the `LoadFromXaml` extension method. This feature can be safely turned off when all XAML resources are compiled using XamlC (see [XAML compilation](https://learn.microsoft.com/en-us/dotnet/maui/xaml/xamlc)). This feature is enabled by default for all configurations except for NativeAOT. | | ||
|
||
## MauiXamlRuntimeParsingSupport | ||
|
||
When this feature is disabled, the following APIs are affected: | ||
- [`LoadFromXaml` extension methods](https://learn.microsoft.com/en-us/dotnet/maui/xaml/runtime-load) will throw runtime exceptions. | ||
- [Disabling XAML compilation](https://learn.microsoft.com/en-us/dotnet/maui/xaml/xamlc#disable-xaml-compilation) using `[XamlCompilation(XamlCompilationOptions.Skip)]` on pages and controls or whole assemblies will cause runtime exceptions. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<linker> | ||
<assembly fullname="Microsoft.Maui"> | ||
<type fullname="Microsoft.Maui.RuntimeFeature"> | ||
<method signature="System.Boolean get_IsXamlRuntimeParsingSupported()" body="stub" feature="Microsoft.Maui.RuntimeFeature.IsXamlRuntimeParsingSupported" value="false" featurevalue="false" /> | ||
<method signature="System.Boolean get_IsXamlRuntimeParsingSupported()" body="stub" feature="Microsoft.Maui.RuntimeFeature.IsXamlRuntimeParsingSupported" value="true" featurevalue="true" /> | ||
</type> | ||
</assembly> | ||
</linker> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System; | ||
|
||
namespace Microsoft.Maui | ||
{ | ||
/// <summary> | ||
/// Contains all the runtime feature switches that are used throught the MAUI codebase. | ||
/// See <see href="https://github.com/dotnet/runtime/blob/main/docs/workflow/trimming/feature-switches.md" /> | ||
/// for examples of how to add new feature switches. | ||
/// </summary> | ||
/// <remarks> | ||
/// Property names must be kept in sync with ILLink.Substitutions.xml for proper value substitutions. | ||
/// Mapping of MSBuild properties to feature switches and the default values of feature switches | ||
/// is defined in Microsoft.Maui.Sdk.Before.targets. | ||
/// </remarks> | ||
internal static class RuntimeFeature | ||
{ | ||
private const bool IsXamlRuntimeParsingSupportedByDefault = true; | ||
|
||
internal static bool IsXamlRuntimeParsingSupported | ||
=> AppContext.TryGetSwitch("Microsoft.Maui.RuntimeFeature.IsXamlRuntimeParsingSupported", out bool isEnabled) | ||
? isEnabled | ||
: IsXamlRuntimeParsingSupportedByDefault; | ||
} | ||
} |
Oops, something went wrong.