@@ -92,6 +92,35 @@ public void TestCodeBehindGenerator_AggregatedXmlns()
9292 Assert . IsTrue ( generated . Contains ( "global::Microsoft.Maui.Controls.Label label" , StringComparison . Ordinal ) ) ;
9393 }
9494
95+ [ Test ]
96+ public void TestCodeBehindGenerator_AggregatedXmlnsOnRD ( )
97+ {
98+ var xaml =
99+ """
100+ <?xml version="1.0" encoding="UTF-8"?>
101+ <ResourceDictionary
102+ xmlns="http://schemas.microsoft.com/dotnet/maui/global"
103+ xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">
104+ <x:String x:Key="MyString">Hello MAUI!</x:String>
105+ </ResourceDictionary>
106+ """ ;
107+
108+ var code =
109+ """
110+ using Microsoft.Maui.Controls;
111+ [assembly: XmlnsDefinition("http://schemas.microsoft.com/dotnet/maui/global", "http://schemas.microsoft.com/dotnet/2021/maui")]
112+ """ ;
113+ var compilation = CreateMauiCompilation ( ) ;
114+ compilation = compilation . AddSyntaxTrees ( CSharpSyntaxTree . ParseText ( code ) ) ;
115+ var result = RunGenerator < CodeBehindGenerator > ( compilation , new AdditionalXamlFile ( "Test.xaml" , xaml ) ) ;
116+
117+ Assert . IsFalse ( result . Diagnostics . Any ( ) ) ;
118+
119+ var generated = result . Results . Single ( ) . GeneratedSources . Single ( gs => gs . HintName . EndsWith ( ".sg.cs" ) ) . SourceText . ToString ( ) ;
120+
121+ Assert . IsTrue ( generated . Contains ( "public partial class __Type" , StringComparison . Ordinal ) ) ;
122+ }
123+
95124 public void TestCodeBehindGenerator_LocalXaml ( [ Values ] bool resolvedType )
96125 {
97126 var xaml =
@@ -305,9 +334,11 @@ public void TestCodeBehindGenerator_NotXaml()
305334</foo>
306335""" ;
307336 var compilation = SourceGeneratorDriver . CreateMauiCompilation ( ) ;
337+ compilation = compilation . AddSyntaxTrees ( CSharpSyntaxTree . ParseText ( "[assembly: global::Microsoft.Maui.Controls.Xaml.Internals.AllowImplicitXmlnsDeclaration]" ) ) ;
308338 var result = SourceGeneratorDriver . RunGenerator < CodeBehindGenerator > ( compilation , new AdditionalXamlFile ( "Test.xaml" , xaml ) ) ;
309339
310- Assert . That ( result . Diagnostics . Any ( ) ) ;
340+ var generated = result . Results . Single ( ) . GeneratedSources . Single ( gs => gs . HintName . EndsWith ( ".sg.cs" ) ) . SourceText . ToString ( ) ;
341+ Assert . That ( result . Diagnostics . Any ( ) || string . IsNullOrWhiteSpace ( generated ) ) ;
311342 }
312343
313344 [ Test ]
0 commit comments