-
Notifications
You must be signed in to change notification settings - Fork 1.8k
XAML xmlns simplifications #29579
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
XAML xmlns simplifications #29579
Conversation
Allow aggregating multiple xmlns into a single new global http://schemas.microsoft.com/dotnet/maui/global using XmlnsDefinition attribute, like this ```csharp [assembly: XmlnsDefinition("http://schemas.microsoft.com/dotnet/maui/global", "http://schemas.microsoft.com/dotnet/2021/maui")] ``` the x: xmlns can not be aggregated, as it serves important purposes for the parsers this also brings #28090 to fix #28150 - fixes #28150 - fixes #28843 - closes #28090
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Adds a new global XAML xmlns, enables implicit xmlns declarations via a preview feature flag, protects built-in xmlns entries, and updates related source generators and metadata.
- Introduces
AllowImplicitXmlnsDeclarationAttribute
and wiring in build tasks to support implicit/default xmlns usage. - Changes
XmlnsDefinitionAttribute
constructor parameter name and surfaces a newTarget
property. - Updates public API shipped/unshipped files, documentation, and solution to expose new types and behaviors.
Reviewed Changes
Copilot reviewed 42 out of 42 changed files in this pull request and generated 5 comments.
Show a summary per file
File | Description |
---|---|
PublicAPI/netstandard/PublicAPI.Shipped.txt | Updated XmlnsDefinitionAttribute ctor signature |
PublicAPI/net/*.Unshipped.txt & *.Shipped.txt (all platforms) | Added AllowImplicitXmlnsDeclarationAttribute and Target API |
Properties/AssemblyInfo.cs | Re-added x: xmlns prefix for XAML |
AllowImplicitXmlnsDeclarationAttribute.cs | New attribute to opt into implicit xmlns support |
Build.Tasks/XmlTypeExtensions.cs | Extended XML namespace gathering and added prefix extraction |
Build.Tasks/XamlTask.cs | Wired implicit xmlns logic into XAML parsing |
Build.Tasks/XamlCTask.cs | Updated XAML compilation to pass module context |
docs/XmlnsDefinitionAttribute.xml | Updated ctor sig in docs and added Target member |
Microsoft.Maui-vscode.sln | Included new SourceGen unit test project |
Comments suppressed due to low confidence (1)
src/Controls/src/Build.Tasks/XmlTypeExtensions.cs:45
- The new logic protecting built-in xmlns definitions and throwing BuildException on invalid entries lacks corresponding unit tests. Please add tests covering both allowed and prohibited XmlnsDefinitionAttribute scenarios to validate this behavior.
if ( attribute.XmlNamespace != XamlParser.MauiGlobal
src/Controls/docs/Microsoft.Maui.Controls/XmlnsDefinitionAttribute.xml
Outdated
Show resolved
Hide resolved
protect maui and x: xmlns from overloading. - fixes #28836
e9afcd0
to
adecc94
Compare
7775f78
to
302c11b
Compare
dd36fc7
to
5172f61
Compare
Description of Change
This PR includes multiple changes related to xmlns, as tracked by #28836.
New global xmlns
http://schemas.microsoft.com/dotnet/maui/global
is a new xmlns that you can use to aggregate multiple xmlns together.The scope of it is local to the project.
By default, it contains the maui xmlns (sourcegenerated) YourNamespace and YourNamespace.Pages (enabled by the updated template.
You can extend this in e.g. GlobalXmlns.cs added by the template (#29203), or adding assembly level XmlnsDefinition anywhere.
You can ad CLR namespaces as usual, but also other xmlns
[assembly:XmlnsDefinition("http://schemas.microsoft.com/dotnet/maui/global", "http://mycompany.com/schema/myxmlns")]
That global xmlns also have a XmlnsPrefix "global" associated to it.
IMPORTANT NOTE: you can not aggregate the x xmlns into the global one. It plays a special role for the parsers and inflators.
This change is implemented using a source generator, so there's no requirement to change any other tool consuming xaml making use of this
Make the xmlns delcarations in XAML implicit
The XAML inflators uses the global xmlns as default, and preloads all other xmlns declared by a XmlnsDefinition that also have a XmlnsPrefix attribute. e.g. the x: prefix is there to be used without the need of being declared.
This part is opt-in, you can enable it by setting
in your
.csproj
Protect some xmlns
with a fix for #28150, it becomes necessary to avoid the overload of the maui, and x, xmlns namespaces.
Issues Fixed
fixes make the default xmlns declaration optional #28849
fixes pre-defined xmlns prefixes #28850
fixes Implicit global xmlns #28847
fixes XAML xmlns simplifications #28836
fixes XmlnsDefinitonAttribute is not supported for "this" assembly #28150
fixes xmlns aggregation #28843
fixes protect maui xmlns from overloading #28839
closes Support XmlnsDefinitionAttribute in "this" assembly #28090
closes [X] implicit xmlns declarations #29181
closes [X] global xmlns #28969
closes [X] Protect some xmlns #28909