Conditional Content Based Upon Configuration

tentux picture tentux · Nov 14, 2011 · Viewed 9k times · Source

I've tried several times to use a similar technique as "conditional references" for conditional content.

Content entries in the Visual Studio Project file such as "web.config" I do not want included when I publish the website.

I've tried a few things like...

<Choose>

    <When Condition="$(Configuration) != 'Release'">
        <ItemGroup>
            <Content Include="web.config">
                <SubType>Designer</SubType>
                <CopyToOutputDirectory>Always</CopyToOutputDirectory>
                 </Content>
        </ItemGroup>
    </When>
    <Otherwise>
        <ItemGroup>
        </ItemGroup>
    </Otherwise>

</Choose>

But this doesn't work. Any ideas? Or have you encountered this before and solved it?

Answer

Nick Nieslanik picture Nick Nieslanik · Nov 14, 2011

I believe you can just add the Condition to the ItemGroup... Example:

    <ItemGroup Condition="'$(Configuration)' != 'Release'"> 
        <Content Include="web.config"> 
            <SubType>Designer</SubType> 
            <CopyToOutputDirectory>Always</CopyToOutputDirectory> 
             </Content> 
    </ItemGroup> 

Note the ticks around '$(Configuration)' in the condition. Those are very necessary.