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 d5bc45c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 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

0 comments on commit d5bc45c

Please sign in to comment.