Conditional Content Based Upon Configuration

风格不统一 提交于 2019-11-27 21:45:05

问题


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?


回答1:


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.




回答2:


I would like to extend the answer provided by Nick Nieslanik with some details just so others aren't stumped in the same way I was.

The solution works during build/publish, but Visual Studio 2010's interface may not reflect the changes made. Whether this is a defect or not, I am not sure, but it did confuse me and it may confuse others.



来源:https://stackoverflow.com/questions/8115696/conditional-content-based-upon-configuration

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!