SanitizeProjectNode's ItemDefinitionGroup processing ignores Conditions
See original GitHub issueI have the following in a shared .props file which my vcxproj files import:
<ItemDefinitionGroup>
<ClCompile>
<DebugVisualStudioVersion>$(VisualStudioVersion)</DebugVisualStudioVersion>
<LanguageStandard>stdcpp17</LanguageStandard>
<!--VS2022-->
<LanguageStandard Condition="$(VisualStudioVersion)=='17.0'">stdcpp20</LanguageStandard>
I was scratching my head wondering why I was getting the following output under VS2017 (hence why I added DebugVisualStudioVersion)
VERBOSE: [CONTEXT] item namespace = @(ClCompile)
VERBOSE: [CONTEXT] propSet: DebugVisualStudioVersion = 15.0
VERBOSE: [CONTEXT] propSet: LanguageStandard = stdcpp17
VERBOSE: [CONTEXT] propSet: LanguageStandard = stdcpp20
In SanitizeProjectNode, there’s this code
if ($node.Name -ieq "ItemDefinitionGroup")
{
foreach ($child in $node.ChildNodes)
{
if ($child.GetType().Name -ine "XmlElement")
{
continue
}
Push-ProjectItemContext $child.Name
foreach ($propNode in $child.ChildNodes)
{
if ($propNode.GetType().Name -ine "XmlElement")
{
continue
}
[string] $propVal = Evaluate-MSBuildExpression $propNode.InnerText
Set-ProjectItemProperty $propNode.Name $propVal
}
Pop-ProjectItemContext
}
}
Unlike in other places, $propNode
is not tested to see if it contains a Condition attribute, so CPT ends up evaluating all properties, no matter what.
This also makes settings which inherit previous values pile up
<PreprocessorDefinitions Condition=" '$(Configuration)' == 'Debug' ">_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions Condition=" '$(Configuration)' != 'Debug' ">NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
Both debug and no debug 😨
VERBOSE: [CONTEXT] propSet: PreprocessorDefinitions = _DEBUG;
VERBOSE: [CONTEXT] propSet: PreprocessorDefinitions = NDEBUG;_DEBUG;
Issue Analytics
- State:
- Created 9 months ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
ItemDefinitionGroup Element (MSBuild)
Learn how MSBuild uses the ItemDefinitionGroup element to define a set of item definitions, metadata values that are applied to all items in ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thank you, Marina! I look forward to using the latest update this week 😄 !
Hi @kornman00,
The fix for this problem is available in release v2023 for Clang Power Tools
Thank you for your help, means a lot for our product
Have a nice day, Marina