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 12, 2023
1 parent dfd0004 commit e460eef
Show file tree
Hide file tree
Showing 3 changed files with 5 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
2 changes: 1 addition & 1 deletion src/Controls/src/Build.Tasks/XamlCTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static void LogWarningOrError(this TaskLoggingHelper loggingHelper, int c
if ((Context.TreatWarningsAsErrors && !Context.WarningsNotAsErrors.Contains(code)) || Context.WarningsAsErrors.Contains(code))
loggingHelper.LogError($"XamlC {code:0000}" , null, null, xamlFilePath, lineNumber, linePosition, endLineNumber, endLinePosition, message, messageArgs);
else
loggingHelper.LogWarning($"XamlC {code:0000}", xamlFilePath, lineNumber, linePosition, endLineNumber, endLinePosition, message, messageArgs);
loggingHelper.LogWarning($"XamlC {code:0000}", null, null, xamlFilePath, lineNumber, linePosition, endLineNumber, endLinePosition, message, messageArgs);
}

}
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 e460eef

Please sign in to comment.