Add MauiXamlHotReload property for IDE communication#34028
Add MauiXamlHotReload property for IDE communication#34028StephaneDelcroix wants to merge 1 commit intodotnet:net11.0from
Conversation
Introduces the MauiXamlHotReload MSBuild property to communicate to the IDE which type of XAML Hot Reload implementation the application expects. Values: - Legacy (default): Traditional XAML Hot Reload - SourceGen: Source generator-based XAML Hot Reload (experimental) When SourceGen is selected, a warning (MAUI1002) is emitted indicating this feature is experimental and not yet fully implemented. This property exists to facilitate migration from legacy XAML Hot Reload to the source generator-based approach. In a future release, Legacy may be deprecated with SourceGen becoming the only supported mode. Fixes dotnet#34027
There was a problem hiding this comment.
Pull request overview
Adds a new MSBuild property, MauiXamlHotReload, intended as an IDE-facing signal for which XAML Hot Reload implementation the app expects (Legacy vs SourceGen), and emits a build warning when opting into the experimental SourceGen mode.
Changes:
- Introduce
MauiXamlHotReloadwith default valueLegacy. - Add an MSBuild validation target that emits warning
MAUI1002whenMauiXamlHotReload=SourceGen.
| <!-- Warn when MauiXamlHotReload is set to SourceGen (not yet fully implemented) --> | ||
| <Target Name="_ValidateMauiXamlHotReload" BeforeTargets="_CheckForInvalidConfigurationAndPlatform" Condition="'$(MauiXamlHotReload)' == 'SourceGen'"> | ||
| <Warning | ||
| Code="MAUI1002" | ||
| Text="MauiXamlHotReload is set to 'SourceGen'. Source generator-based XAML Hot Reload is experimental and not yet fully implemented. Use at your own risk." /> |
There was a problem hiding this comment.
The _ValidateMauiXamlHotReload target only checks for an exact, case-sensitive match to SourceGen. This means values like sourcegen, SourceGen (trailing space), or typos (e.g., Sourcegen) will silently bypass the warning and may lead to IDE misconfiguration. Consider normalizing (trim + case-insensitive compare) and also emitting an error/warning for any value other than Legacy/SourceGen to make misconfiguration obvious.
| <!-- Warn when MauiXamlHotReload is set to SourceGen (not yet fully implemented) --> | |
| <Target Name="_ValidateMauiXamlHotReload" BeforeTargets="_CheckForInvalidConfigurationAndPlatform" Condition="'$(MauiXamlHotReload)' == 'SourceGen'"> | |
| <Warning | |
| Code="MAUI1002" | |
| Text="MauiXamlHotReload is set to 'SourceGen'. Source generator-based XAML Hot Reload is experimental and not yet fully implemented. Use at your own risk." /> | |
| <!-- Warn when MauiXamlHotReload is set to SourceGen (not yet fully implemented) and validate allowed values --> | |
| <Target Name="_ValidateMauiXamlHotReload" BeforeTargets="_CheckForInvalidConfigurationAndPlatform"> | |
| <PropertyGroup> | |
| <!-- Normalize MauiXamlHotReload for comparison (trim + case-insensitive) --> | |
| <_MauiXamlHotReloadNormalized>$([System.String]::Copy('$(MauiXamlHotReload)').Trim())</_MauiXamlHotReloadNormalized> | |
| <_MauiXamlHotReloadIsSourceGen Condition="'$([System.String]::Copy('$(_MauiXamlHotReloadNormalized)').ToUpperInvariant())' == 'SOURCEGEN'">true</_MauiXamlHotReloadIsSourceGen> | |
| <_MauiXamlHotReloadIsLegacy Condition="'$([System.String]::Copy('$(_MauiXamlHotReloadNormalized)').ToUpperInvariant())' == 'LEGACY'">true</_MauiXamlHotReloadIsLegacy> | |
| </PropertyGroup> | |
| <!-- Preserve existing warning when MauiXamlHotReload is (normalized) SourceGen --> | |
| <Warning | |
| Code="MAUI1002" | |
| Text="MauiXamlHotReload is set to 'SourceGen'. Source generator-based XAML Hot Reload is experimental and not yet fully implemented. Use at your own risk." | |
| Condition="'$(_MauiXamlHotReloadIsSourceGen)' == 'true'" /> | |
| <!-- Warn on any unrecognized MauiXamlHotReload value --> | |
| <Warning | |
| Code="MAUI1003" | |
| Text="MauiXamlHotReload is set to an unrecognized value '$(MauiXamlHotReload)'. Supported values are 'Legacy' and 'SourceGen'." | |
| Condition="'$(_MauiXamlHotReloadNormalized)' != '' and '$(_MauiXamlHotReloadIsSourceGen)' != 'true' and '$(_MauiXamlHotReloadIsLegacy)' != 'true'" /> |
| <Target Name="_ValidateMauiXamlHotReload" BeforeTargets="_CheckForInvalidConfigurationAndPlatform" Condition="'$(MauiXamlHotReload)' == 'SourceGen'"> | ||
| <Warning | ||
| Code="MAUI1002" | ||
| Text="MauiXamlHotReload is set to 'SourceGen'. Source generator-based XAML Hot Reload is experimental and not yet fully implemented. Use at your own risk." /> | ||
| </Target> |
There was a problem hiding this comment.
This PR introduces a new build warning (MAUI1002) and a new MSBuild property default. There are existing MSBuild unit tests validating Microsoft.Maui.Controls.targets behavior (e.g., src/Controls/tests/Xaml.UnitTests/MSBuild/MSBuildTests.cs). Please add coverage that asserts MAUI1002 is (a) not emitted by default and (b) emitted when /p:MauiXamlHotReload=SourceGen is set, so future target changes don’t accidentally remove/rename the signal IDEs rely on.
Description
Introduces the
MauiXamlHotReloadMSBuild property to communicate to the IDE which type of XAML Hot Reload implementation the application expects.Values
Legacy(default)SourceGenUsage
IDE Behavior
When
MauiXamlHotReload=Legacy(Default)The IDE should behave as it currently does:
When
MauiXamlHotReload=SourceGenThe IDE MUST:
The IDE MUST NOT:
The IDE MAY continue to support:
Warning
When
MauiXamlHotReload=SourceGenis set, warning MAUI1002 is emitted:Migration Note
This property exists to facilitate migration from legacy XAML Hot Reload to the source generator-based approach. In a future release,
Legacymay be deprecated withSourceGenbecoming the only supported mode.Fixes #34027