question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SanitizeProjectNode's ItemDefinitionGroup processing ignores Conditions

See original GitHub issue

I 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:closed
  • Created 9 months ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
kornman00commented, Feb 7, 2023

Thank you, Marina! I look forward to using the latest update this week 😄 !

0reactions
mariru27commented, Feb 1, 2023

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found