Skip to content

Commit 6d44bcb

Browse files
wip
1 parent 7c7d51c commit 6d44bcb

File tree

415 files changed

+376
-698
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

415 files changed

+376
-698
lines changed

Directory.Build.props

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22
<Import Project="Sdk.props" Sdk="Microsoft.DotNet.Arcade.Sdk" />
33
<Import Condition="'$(EnvironmentBuildPropsImported)' != 'True'" Project="$(MSBuildThisFileDirectory)eng\Environment.Build.props" />
44

5+
<PropertyGroup>
6+
<!--
7+
Keep backward compatibility with XamlC, XamlCompilationAttribute, and xaml-comp processing instruction
8+
When we're ready to turn this off, we can remove all code depending on this condition, and drop this property group
9+
-->
10+
11+
<_MauiXamlSourceGenBackCompat>true</_MauiXamlSourceGenBackCompat>
12+
<DefineConstants Condition=" '$(_MauiXamlSourceGenBackCompat)' == 'true' ">$(DefineConstants);_MAUIXAML_SOURCEGEN_BACKCOMPAT</DefineConstants>
13+
</PropertyGroup>
14+
515
<PropertyGroup>
616
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
717
<!-- Detailed trimmer warnings, if present -->

src/Controls/samples/Controls.Sample.Embedding/Resources/Styles/Colors.xaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
2-
<?xaml-comp compile="true" ?>
32
<ResourceDictionary
43
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
54
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">

src/Controls/samples/Controls.Sample.Embedding/Resources/Styles/Styles.xaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
2-
<?xaml-comp compile="true" ?>
32
<ResourceDictionary
43
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
54
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">

src/Controls/src/Build.Tasks/XamlCTask.cs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,11 @@ public override bool Execute(out IList<Exception> thrownExceptions)
214214
&& (bool)xamlProcessingAttr.ConstructorArguments[1].Value;
215215
assemblyInflatorOptions = (generateInflatorSwitch, inflator);
216216
if (!generateInflatorSwitch)
217-
skipassembly = (inflator & XamlInflator.XamlC) != XamlInflator.XamlC && inflator != XamlInflator.Default;
217+
skipassembly = (inflator & XamlInflator.XamlC) != XamlInflator.XamlC;
218218

219219
}
220220

221-
#pragma warning disable CS0618 // Type or member is obsolete
221+
#if _MAUIXAML_SOURCEGEN_BACKCOMPAT
222222
CustomAttribute xamlcAttr = null;
223223
if (assemblyDefinition.HasCustomAttributes &&
224224
(xamlcAttr =
@@ -236,9 +236,10 @@ public override bool Execute(out IList<Exception> thrownExceptions)
236236
else
237237
LoggingHelper.LogWarning($"{new string(' ', 2)}Assembly has both XamlCompilationAttribute and XamlProcessingAttribute. XamlCompilationAttribute will be ignored.");
238238
}
239-
#pragma warning restore CS0618 // Type or member is obsolete
240239

241-
xamlcAttr = xamlProcessingAttr = null;
240+
xamlcAttr = null;
241+
#endif
242+
xamlProcessingAttr = null;
242243

243244
foreach (var module in assemblyDefinition.Modules)
244245
{
@@ -255,10 +256,10 @@ public override bool Execute(out IList<Exception> thrownExceptions)
255256
&& (bool)xamlProcessingAttr.ConstructorArguments[1].Value;
256257
moduleInflatorOptions = (generateInflatorSwitch, inflator);
257258
if (!generateInflatorSwitch)
258-
skipmodule = (inflator & XamlInflator.XamlC) != XamlInflator.XamlC && inflator != XamlInflator.Default;
259+
skipmodule = (inflator & XamlInflator.XamlC) != XamlInflator.XamlC;
259260
}
260261

261-
#pragma warning disable CS0618 // Type or member is obsolete
262+
#if _MAUIXAML_SOURCEGEN_BACKCOMPAT
262263
if (module.HasCustomAttributes &&
263264
(xamlcAttr =
264265
module.CustomAttributes.FirstOrDefault(
@@ -276,9 +277,9 @@ public override bool Execute(out IList<Exception> thrownExceptions)
276277
else
277278
LoggingHelper.LogWarning($"{new string(' ', 2)}Module {module.Name} has both XamlCompilationAttribute and XamlProcessingAttribute. XamlCompilationAttribute will be ignored.");
278279
}
279-
#pragma warning restore CS0618 // Type or member is obsolete
280-
281-
xamlcAttr = xamlProcessingAttr = null;
280+
xamlcAttr = null;
281+
#endif
282+
xamlProcessingAttr = null;
282283

283284
LoggingHelper.LogMessage(Low, $"{new string(' ', 2)}Module: {module.Name}");
284285
var resourcesToPrune = new List<EmbeddedResource>();
@@ -313,13 +314,13 @@ public override bool Execute(out IList<Exception> thrownExceptions)
313314
typeInflatorOptions = (generateInflatorSwitch, inflator);
314315
if (generateInflatorSwitch)
315316
{
316-
skiptype = (inflator & XamlInflator.XamlC) != XamlInflator.XamlC && inflator != XamlInflator.Default;
317+
skiptype = (inflator & XamlInflator.XamlC) != XamlInflator.XamlC;
317318
initCompName = "InitializeComponentXamlC";
318319
}
319320
else
320321
skiptype = inflator != XamlInflator.XamlC;
321322
}
322-
#pragma warning disable CS0618 // Type or member is obsolete
323+
#if _MAUIXAML_SOURCEGEN_BACKCOMPAT
323324
if (typeDef.HasCustomAttributes &&
324325
(xamlcAttr =
325326
typeDef.CustomAttributes.FirstOrDefault(
@@ -338,9 +339,9 @@ public override bool Execute(out IList<Exception> thrownExceptions)
338339
else
339340
LoggingHelper.LogWarning($"{new string(' ', 6)}Type {typeDef.Name} has both XamlCompilationAttribute and XamlProcessingAttribute. XamlCompilationAttribute will be ignored.");
340341
}
341-
#pragma warning restore CS0618 // Type or member is obsolete
342-
343-
xamlcAttr = xamlProcessingAttr = null;
342+
xamlcAttr = null;
343+
#endif
344+
xamlProcessingAttr = null;
344345

345346
if (Type != null)
346347
skiptype = !(Type == classname);

src/Controls/src/Build.Tasks/nuget/buildTransitive/netstandard2.0/Microsoft.Maui.Controls.Common.targets

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@
2222
<CompilerVisibleItemMetadata Include="AdditionalFiles" MetadataName="ManifestResourceName" />
2323
<CompilerVisibleItemMetadata Include="AdditionalFiles" MetadataName="TargetPath" />
2424
<CompilerVisibleItemMetadata Include="AdditionalFiles" MetadataName="RelativePath" />
25+
<CompilerVisibleItemMetadata Include="AdditionalFiles" MetadataName="Inflator" />
26+
<CompilerVisibleProperty Include="MauiXamlNoWarn" />
27+
<CompilerVisibleItemMetadata Include="AdditionalFiles" MetadataName="NoWarn" />
28+
<CompilerVisibleProperty Include="MauiXamlEnableDiagnostics" />
29+
<CompilerVisibleItemMetadata Include="AdditionalFiles" MetadataName="EnableDiagnostics" />
30+
<CompilerVisibleProperty Include="MauiXamlLineInfo" />
31+
<CompilerVisibleItemMetadata Include="AdditionalFiles" MetadataName="LineInfo" />
32+
<CompilerVisibleProperty Include="MauiXamlNullable" />
33+
<CompilerVisibleItemMetadata Include="AdditionalFiles" MetadataName="Nullable" />
2534
</ItemGroup>
26-
2735
</Project>

src/Controls/src/Build.Tasks/nuget/buildTransitive/netstandard2.0/Microsoft.Maui.Controls.targets

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
<SynthesizeLinkMetadata>true</SynthesizeLinkMetadata>
77
<EnableDefaultXamlItems Condition="'$(EnableDefaultXamlItems)'==''">True</EnableDefaultXamlItems>
88
<EnableDefaultCssItems Condition="'$(EnableDefaultCssItems)'==''">True</EnableDefaultCssItems>
9+
<!-- default MauiXaml inflators -->
10+
<_MauiXamlInflator Condition="' $(MauiXamlInflator)' != '' ">$(MauiXamlInflator)</_MauiXamlInflator>
11+
<_MauiXamlInflator Condition=" '$(MauiXamlInflator)' == '' And '$(Configuration)' == 'Debug' ">Runtime</_MauiXamlInflator>
12+
<_MauiXamlInflator Condition=" '$(MauiXamlInflator)' == '' And '$(Configuration)' != 'Debug' ">XamlC</_MauiXamlInflator>
13+
914
<!-- The WINUI check for this only runs when there is an empty string so I just convert false to an empty string to fall in line with our other properties -->
1015
<SkipMicrosoftUIXamlCheckTargetPlatformVersion Condition="'$(SkipMicrosoftUIXamlCheckTargetPlatformVersion)'==''">true</SkipMicrosoftUIXamlCheckTargetPlatformVersion>
1116
<SkipMicrosoftUIXamlCheckTargetPlatformVersion Condition="'$(SkipMicrosoftUIXamlCheckTargetPlatformVersion)'=='false'"></SkipMicrosoftUIXamlCheckTargetPlatformVersion>
@@ -73,11 +78,34 @@
7378
Condition="'$(_XFTargetsImported)' == 'true'"/>
7479
</Target>
7580

81+
<Target Name="_MauiXamlComputeInflator">
82+
<ItemGroup>
83+
<!-- Assign the default inflator to MauiXaml that don't have any -->
84+
<!-- there's a roslyn bug that stops parsing value at the first semicolon. replace them all https://github.com/dotnet/roslyn/issues/43970 -->
85+
<MauiXaml Inflator="$([MSBuild]::ValueOrDefault('%(MauiXaml.Inflator)','$(_MauiXamlInflator)').Replace(';', ','))"/>
86+
87+
<_MauiXaml_SG Remove="@(_MauiXaml_SG)" />
88+
<_MauiXaml_RT Remove="@(_MauiXaml_RT)" />
89+
<_MauiXaml_XC Remove="@(_MauiXaml_XC)" />
90+
<_MauiXaml_SG Include="@(MauiXaml)" Condition="$([System.String]::new('%(MauiXaml.Inflator)').Contains('SourceGen', StringComparison.OrdinalIgnoreCase))" />
91+
<_MauiXaml_RT Include="@(MauiXaml)" Condition="$([System.String]::new('%(MauiXaml.Inflator)').Contains('Runtime', StringComparison.OrdinalIgnoreCase))" />
92+
<_MauiXaml_XC Include="@(MauiXaml)" Condition="$([System.String]::new('%(MauiXaml.Inflator)').Contains('XamlC', StringComparison.OrdinalIgnoreCase))" />
93+
<_MauiXaml_AsEmbeddedResource Include="@(_MauiXaml_RT)" />
94+
<_MauiXaml_AsEmbeddedResource Include="@(_MauiXaml_XC)" KeepDuplicates="false" />
95+
</ItemGroup>
96+
</Target>
7697

7798
<!-- Inject MauiXaml and MauiCss as AdditionalFiles for partial type generation-->
99+
<PropertyGroup>
100+
<_MauiInjectXamlCssAdditionalFilesDependsOn>
101+
_MauiXamlComputeInflator;
102+
$(CreateManifestResourceNamesDependsOn);
103+
</_MauiInjectXamlCssAdditionalFilesDependsOn>
104+
</PropertyGroup>
105+
78106
<Target Name="_MauiInjectXamlCssAdditionalFiles"
79107
BeforeTargets="GenerateMSBuildEditorConfigFileShouldRun"
80-
DependsOnTargets="$(CreateManifestResourceNamesDependsOn)">
108+
DependsOnTargets="$(_MauiInjectXamlCssAdditionalFilesDependsOn)">
81109
<ItemGroup>
82110
<_MauiXamlWithResourceNames Remove="@(_MauiXamlWithResourceNames)" />
83111
<_MauiXamlWithTargetPath Remove="@(_MauiXamlWithTargetPath)" />
@@ -113,6 +141,7 @@
113141
TargetPath="%(_MauiXamlWithResourceNames.TargetPath)"
114142
RelativePath="$([MSBuild]::MakeRelative($(MSBuildProjectDirectory), %(_MauiXamlWithResourceNames.TargetPath)))"
115143
ItemSpec="%(_MauiXamlWithResourceNames.OriginalItemSpec)"
144+
Inflator="%(_MauiXamlWithResourceNames.Inflator)"
116145
GenKind="Xaml"/>
117146
<AdditionalFiles Condition="%(_MauiCssWithResourceNames.TargetPath) != ''"
118147
Include="@(_MauiCssWithResourceNames)"
@@ -129,14 +158,19 @@
129158
</Target>
130159

131160

132-
<!-- re-add MauiXaml and MauiCss as EmbeddedResources -->
161+
<!-- re-add MauiXaml and MauiCss as EmbeddedResources for runtime inflation and XamlC -->
133162
<PropertyGroup>
134163
<PrepareResourcesDependsOn>
135164
_MauiAddXamlEmbeddedResources;
136165
$(PrepareResourcesDependsOn);
137166
</PrepareResourcesDependsOn>
167+
<_MauiAddXamlEmbeddedResourcesDependsOn>
168+
_MauiXamlComputeInflator
169+
</_MauiAddXamlEmbeddedResourcesDependsOn>
138170
</PropertyGroup>
139-
<Target Name="_MauiAddXamlEmbeddedResources">
171+
172+
<Target Name="_MauiAddXamlEmbeddedResources"
173+
DependsOnTargets="$(_MauiAddXamlEmbeddedResourcesDependsOn)">
140174
<ItemGroup>
141175
<EmbeddedResource Include="@(MauiXaml)" />
142176
<EmbeddedResource Include="@(MauiCss)" />

src/Controls/src/SourceGen/CodeBehindCodeWriter.cs

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,22 @@ public static string GenerateXamlCodeBehind(XamlProjectItemForCB? xamlItem, Comp
7070

7171
var rootSymbol = compilation.GetTypeByMetadataName($"{rootClrNamespace}.{rootType}");
7272

73-
(var generateInflatorSwitch, var xamlInflators, _) = rootSymbol?.GetXamlProcessing() ?? (false, XamlInflator.Default, false);
73+
var generateInflatorSwitch = compilation.AssemblyName == "Microsoft.Maui.Controls.Xaml.UnitTests";
74+
var xamlInflators = projItem.Inflator;
75+
76+
//if there's only the XamlC inflator, prevent non-assigned errors
77+
if (xamlInflators == XamlInflator.XamlC)
78+
sb.AppendLine("#pragma warning disable CS0649");
7479

7580
sb.AppendLine($"namespace {rootClrNamespace}");
7681
sb.AppendLine("{");
7782
sb.AppendLine($"\t[global::Microsoft.Maui.Controls.Xaml.XamlFilePath(\"{projItem.RelativePath?.Replace("\\", "\\\\")}\")]");
83+
#if !_MAUIXAML_SOURCEGEN_BACKCOMPAT
7884
if (addXamlCompilationAttribute)
7985
{
8086
sb.AppendLine($"\t[global::Microsoft.Maui.Controls.Xaml.XamlCompilation(global::Microsoft.Maui.Controls.Xaml.XamlCompilationOptions.Compile)]");
8187
}
88+
#endif
8289

8390
if (hideFromIntellisense)
8491
{
@@ -95,10 +102,7 @@ public static string GenerateXamlCodeBehind(XamlProjectItemForCB? xamlItem, Comp
95102
if (generateDefaultCtor)
96103
{
97104
sb.AppendLine($"\t\t[global::System.CodeDom.Compiler.GeneratedCode(\"Microsoft.Maui.Controls.SourceGen\", \"1.0.0.0\")]");
98-
sb.AppendLine($"\t\tpublic {rootType}()");
99-
sb.AppendLine("\t\t{");
100-
sb.AppendLine(generateInflatorSwitch ? "\t\t\tInitializeComponent(global::Microsoft.Maui.Controls.Xaml.XamlInflator.Default);" : "\t\t\tInitializeComponent();");
101-
sb.AppendLine("\t\t}");
105+
sb.AppendLine($"\t\tpublic {rootType}() => InitializeComponent();");
102106
sb.AppendLine();
103107
}
104108

@@ -137,16 +141,8 @@ public static string GenerateXamlCodeBehind(XamlProjectItemForCB? xamlItem, Comp
137141
// - InitializeComponentXamlC will be used for XamlC
138142
// - InitializeComponentSourceGen will be used for SourceGen
139143
// - no parameterless InitializeComponent will be generated
140-
141144
if (!generateInflatorSwitch)
142145
{
143-
if (xamlInflators == XamlInflator.Default)
144-
{
145-
if (projItem.Configuration != null && projItem.Configuration.Equals("Release", StringComparison.OrdinalIgnoreCase))
146-
InitComp("InitializeComponent", empty: true);
147-
else
148-
InitComp("InitializeComponent");
149-
}
150146
if ((xamlInflators & XamlInflator.Runtime) == XamlInflator.Runtime)
151147
InitComp("InitializeComponent");
152148
else if ((xamlInflators & XamlInflator.XamlC) == XamlInflator.XamlC)
@@ -156,14 +152,11 @@ public static string GenerateXamlCodeBehind(XamlProjectItemForCB? xamlItem, Comp
156152
}
157153
else
158154
{
159-
if ((xamlInflators & XamlInflator.Runtime) == XamlInflator.Runtime
160-
|| xamlInflators == XamlInflator.Default)
155+
if ((xamlInflators & XamlInflator.Runtime) == XamlInflator.Runtime)
161156
InitComp("InitializeComponentRuntime");
162-
if ((xamlInflators & XamlInflator.XamlC) == XamlInflator.XamlC
163-
|| xamlInflators == XamlInflator.Default)
157+
if ((xamlInflators & XamlInflator.XamlC) == XamlInflator.XamlC)
164158
InitComp("InitializeComponentXamlC", empty: true);
165-
if ((xamlInflators & XamlInflator.SourceGen) == XamlInflator.SourceGen
166-
|| xamlInflators == XamlInflator.Default)
159+
if ((xamlInflators & XamlInflator.SourceGen) == XamlInflator.SourceGen)
167160
InitComp("InitializeComponentSourceGen", partialsignature: true);
168161
}
169162

@@ -238,36 +231,40 @@ void InitComp(string methodName, bool empty = false, bool partialsignature = fal
238231

239232
sb.AppendLine($"#endif");
240233
}
241-
sb.AppendLine($"\t\tprivate void InitializeComponent() => InitializeComponentRuntime();");
242-
sb.AppendLine();
234+
235+
//this isn't supposed to be used, so the default to the first available inflator
236+
if ((xamlInflators & XamlInflator.Runtime) == XamlInflator.Runtime)
237+
sb.AppendLine($"\t\tprivate void InitializeComponent() => InitializeComponentRuntime();");
238+
else if ((xamlInflators & XamlInflator.SourceGen) == XamlInflator.SourceGen)
239+
sb.AppendLine($"\t\tprivate void InitializeComponent() => InitializeComponentSourceGen();");
240+
else if ((xamlInflators & XamlInflator.XamlC) == XamlInflator.XamlC)
241+
sb.AppendLine($"\t\tprivate void InitializeComponent() => InitializeComponentXamlC();");
242+
243243

244244
sb.AppendLine($"\t\t[global::System.CodeDom.Compiler.GeneratedCode(\"Microsoft.Maui.Controls.SourceGen\", \"1.0.0.0\")]");
245245

246-
sb.AppendLine($"\t\tpublic {rootType}(global::Microsoft.Maui.Controls.Xaml.XamlInflator inflator)");
246+
sb.AppendLine($"\t\tinternal {rootType}(global::Microsoft.Maui.Controls.Xaml.XamlInflator inflator)");
247247
sb.AppendLine("\t\t{");
248248
sb.AppendLine("\t\t\tswitch (inflator)");
249249
sb.AppendLine("\t\t\t{");
250-
if (xamlInflators == XamlInflator.Default || (xamlInflators & XamlInflator.Runtime) == XamlInflator.Runtime)
250+
if ((xamlInflators & XamlInflator.Runtime) == XamlInflator.Runtime)
251251
{
252252
sb.AppendLine("\t\t\t\tcase global::Microsoft.Maui.Controls.Xaml.XamlInflator.Runtime:");
253253
sb.AppendLine("\t\t\t\t\tInitializeComponentRuntime();");
254254
sb.AppendLine("\t\t\t\t\tbreak;");
255255
}
256-
if (xamlInflators == XamlInflator.Default || (xamlInflators & XamlInflator.XamlC) == XamlInflator.XamlC)
256+
if ((xamlInflators & XamlInflator.XamlC) == XamlInflator.XamlC)
257257
{
258258
sb.AppendLine("\t\t\t\tcase global::Microsoft.Maui.Controls.Xaml.XamlInflator.XamlC:");
259259
sb.AppendLine("\t\t\t\t\tInitializeComponentXamlC();");
260260
sb.AppendLine("\t\t\t\t\tbreak;");
261261
}
262-
if (xamlInflators == XamlInflator.Default || (xamlInflators & XamlInflator.SourceGen) == XamlInflator.SourceGen)
262+
if ((xamlInflators & XamlInflator.SourceGen) == XamlInflator.SourceGen)
263263
{
264264
sb.AppendLine("\t\t\t\tcase global::Microsoft.Maui.Controls.Xaml.XamlInflator.SourceGen:");
265265
sb.AppendLine("\t\t\t\t\tInitializeComponentSourceGen();");
266266
sb.AppendLine("\t\t\t\t\tbreak;");
267267
}
268-
sb.AppendLine("\t\t\t\tcase global::Microsoft.Maui.Controls.Xaml.XamlInflator.Default:");
269-
sb.AppendLine("\t\t\t\t\tInitializeComponent();");
270-
sb.AppendLine("\t\t\t\t\tbreak;");
271268
sb.AppendLine("\t\t\t\tdefault:");
272269
sb.AppendLine("\t\t\t\t\tthrow new global::System.NotSupportedException($\"no code for {inflator} generated. check the [XamlProcessing] attribute.\");");
273270
sb.AppendLine("\t\t\t}");
@@ -301,12 +298,14 @@ public static bool TryParseXaml(XamlProjectItemForCB parseResult, string uid, Co
301298
return false;
302299
}
303300

301+
#if _MAUIXAML_SOURCEGEN_BACKCOMPAT
304302
// if the following xml processing instruction is present
305303
//
306304
// <?xaml-comp compile="true" ?>
307305
//
308306
// we will generate a xaml.g.cs file with the default ctor calling InitializeComponent, and a XamlCompilation attribute
309307
var hasXamlCompilationProcessingInstruction = GetXamlCompilationProcessingInstruction(root.OwnerDocument);
308+
#endif
310309

311310
var rootClass = root.Attributes["Class", XamlParser.X2006Uri]
312311
?? root.Attributes["Class", XamlParser.X2009Uri];
@@ -315,6 +314,7 @@ public static bool TryParseXaml(XamlProjectItemForCB parseResult, string uid, Co
315314
{
316315
XmlnsHelper.ParseXmlns(rootClass.Value, out rootType, out rootClrNamespace, out _, out _);
317316
}
317+
#if _MAUIXAML_SOURCEGEN_BACKCOMPAT
318318
else if (hasXamlCompilationProcessingInstruction && root.NamespaceURI == XamlParser.MauiUri)
319319
{
320320
rootClrNamespace = "__XamlGeneratedCode__";
@@ -323,6 +323,7 @@ public static bool TryParseXaml(XamlProjectItemForCB parseResult, string uid, Co
323323
addXamlCompilationAttribute = true;
324324
hideFromIntellisense = true;
325325
}
326+
#endif
326327
else if (parseResult?.ProjectItem?.ManifestResourceName != null && parseResult.ProjectItem.TargetPath != null)
327328
{ // rootClass == null && !hasXamlCompilationProcessingInstruction) {
328329
xamlResourceIdOnly = true; //only generate the XamlResourceId assembly attribute
@@ -345,6 +346,7 @@ public static bool TryParseXaml(XamlProjectItemForCB parseResult, string uid, Co
345346
return true;
346347
}
347348

349+
#if _MAUIXAML_SOURCEGEN_BACKCOMPAT
348350
//true, unless explicitely false
349351
static bool GetXamlCompilationProcessingInstruction(XmlDocument xmlDoc)
350352
{
@@ -358,6 +360,7 @@ static bool GetXamlCompilationProcessingInstruction(XmlDocument xmlDoc)
358360

359361
return true;
360362
}
363+
#endif
361364

362365
internal static string GetWarningDisable(XmlDocument xmlDoc)
363366
{

src/Controls/src/SourceGen/CodeBehindGenerator.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -229,15 +229,9 @@ static bool ShouldGenerateSourceGenInitializeComponent(XamlProjectItemForIC xaml
229229
if (rootType == null)
230230
return false;
231231

232-
(_, var xamlInflators, var set) = rootType.GetXamlProcessing();
232+
var xamlInflators = xamlItem.ProjectItem.Inflator;
233233

234-
//this test must go as soon as 'set' goes away
235-
if (!set)
236-
return false;
237-
238-
if ((xamlInflators & XamlInflator.SourceGen) != XamlInflator.SourceGen
239-
&& xamlInflators != XamlInflator.Default
240-
&& xamlItem.ProjectItem.ForceSourceGen == false)
234+
if ((xamlInflators & XamlInflator.SourceGen) != XamlInflator.SourceGen)
241235
return false;
242236

243237
return true;

0 commit comments

Comments
 (0)