Msbuild: Log a warning when an undefined property is used

Created on 12 Feb 2018  路  5Comments  路  Source: dotnet/msbuild

When an undefined property is used, consider logging a warning or at least a message. In Strict Mode, fail the build.

Debuggability Logging Warning Waves

Most helpful comment

yeah like we have Exists for files and directories, have Defined for properties.

<PropertyGroup>
  <FunProperty Condition="!Defined(FunProperty)">FunDefault</FunProperty>
</PropertyGroup>

All 5 comments

Such a warning would be _incredibly_ noisy.

It would also have to be special cased for the if-not-set-set-to-my-default case

<PropertyGroup>
  <FunProperty Condition="'$(FunProperty)' == ''">FunDefault</FunProperty>
</PropertyGroup>

I think we already have logic to detect that case somewhere, but I don't remember why . ..

You can make a differentiation between when it's used directly like in '$(FunProperty)' or in expression '$(FunProperty)\foo'.
Better pattern to check is property was defined might also help

yeah like we have Exists for files and directories, have Defined for properties.

<PropertyGroup>
  <FunProperty Condition="!Defined(FunProperty)">FunDefault</FunProperty>
</PropertyGroup>

This can be enabled with MSBUILDWARNONUNINITIALIZEDPROPERTY. I presume it wasn't made default when that was implemented in the Stone Age because of noisiness (but we can always reevaluate).

Was this page helpful?
0 / 5 - 0 ratings