Skip to content

Commit

Permalink
[X] Warn on non compiled bindings
Browse files Browse the repository at this point in the history
When XamlC can't compile a Binding due to missing x:DataType, log a
warning.

If you use TreatWarningsAsErrors, add XC10101 to WarningsNotAsErrors to
avoid the build failing
  • Loading branch information
StephaneDelcroix committed Dec 13, 2023
1 parent 2c6be4a commit 27180c4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/Controls/src/Build.Tasks/SetPropertiesVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,10 @@ static IEnumerable<Instruction> CompileBindingPath(ElementNode node, ILContext c
n = n.Parent as IElementNode;
}

if (dataTypeNode is null)
if (dataTypeNode is null) {
context.LoggingHelper.LogWarningOrError(10101, context.XamlFilePath, node.LineNumber, node.LinePosition, 0, 0, $"Binding could be compiled if x:DataType is specified", null);
yield break;
}

if (dataTypeNode is ElementNode enode
&& enode.XmlType.NamespaceUri == XamlParser.X2009Uri
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<AssemblyName>Microsoft.Maui.Controls.Xaml.UnitTests</AssemblyName>
<WarningLevel>4</WarningLevel>
<NoWarn>0672;0219;0414;CS0436;CS0618</NoWarn>
<WarningsNotAsErrors>XC0618</WarningsNotAsErrors>
<WarningsNotAsErrors>XC0618;XC10101</WarningsNotAsErrors>
<IsPackable>false</IsPackable>
<DisableMSBuildAssemblyCopyCheck>true</DisableMSBuildAssemblyCopyCheck>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
<RootNamespace>Microsoft.Maui.TestUtils.DeviceTests.Runners</RootNamespace>
<AssemblyName>Microsoft.Maui.TestUtils.DeviceTests.Runners</AssemblyName>
<!--<Nullable>enable</Nullable>-->
<NoWarn>$(NoWarn),CA1416</NoWarn>
<NoWarn>$(NoWarn);CA1416</NoWarn>
<WarningsNotAsErrors>XC10101</WarningsNotAsErrors>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit 27180c4

Please sign in to comment.