msbuild icon indicating copy to clipboard operation
msbuild copied to clipboard

Support ItemDefinitionGroup in Choose/When

Open ss8104 opened this issue 5 years ago • 3 comments

Steps to reproduce

I am trying to set copy local false in all my projects (outputtype=library)from the Driectory.build.props file in the root folder.

<When Condition=" '$(OutputType)'=='Library' ">
    <ItemDefinitionGroup>
        <Reference>
            <Private>False</Private>
        </Reference>
        <ProjectReference>
            <Private>False</Private>
        </ProjectReference>
    </ItemDefinitionGroup>
</When>
<When Condition=" '$(OutputType)'=='exe' ">
    <ItemDefinitionGroup>
        <Reference>
            <Private>True</Private>
        </Reference>
        <ProjectReference>
            <Private>True</Private>
        </ProjectReference>
    </ItemDefinitionGroup>
</When>

should I be able to use conditional constructs this way? I tried above but get an error

The element <ItemDefinitionGroup> beneath element <When> is unrecognized.

ss8104 avatar Jun 16 '20 21:06 ss8104

Choose/When evidently supports only ItemGroup/PropertyGroup. I don't know why that is, but it's documented.

You'll have to use conditions on the ItemDefinitionGroup instead.

rainersigwald avatar Jun 17 '20 15:06 rainersigwald

https://github.com/dotnet/msbuild/blob/6033e4c95bcd9fa31ebe9b52462c15521cda8f62/src/Build/Evaluation/ProjectParser.cs#L848-L872 reference the code, under when, only support choose, itemGroup, and PropertyGroup currently.

JaynieBai avatar Sep 16 '22 02:09 JaynieBai

I don't know why that is, but it's documented.

I think it was just an oversight at the time.

danmoseley avatar Sep 16 '22 04:09 danmoseley