为什么“条件"属性不适用于“元素组"元素? [英] Why the `Condition` attribute doesn't work for the `ItemGroup` element?

查看:86
本文介绍了为什么“条件"属性不适用于“元素组"元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MS Visual Studio 2013.

MS Visual Studio 2013.

WhenItemGroup元素都可以具有Condition属性(如我在MSDN中所看到的).但是我得到了不同的结果.

Both When and ItemGroup elements can to have the Condition attribute (as I see in MSDN). But I get different results.

$(CAD_Year)为2015时,我预计AcRibbon引用到我的项目:

When $(CAD_Year) is 2015, I expect the AcRibbon will be not referensed to my project:

<ItemGroup Condition= "'$(CAD_Year)' &lt; '2010'" >    
  <Reference Include="AcRibbon">
    <HintPath>$(CAD_SDK_Location)\$(Inc)\AcRibbon.dll</HintPath>
    <Private>False</Private>
  </Reference>
</ItemGroup>

但是我总是在解决方案浏览器中得到未解析的AcRibbon参考.

But I get unresolved reference in the Solution Browser for the AcRibbon always.

但是此变体可以正常工作:

But this variant works fine:

<Choose>
  <When Condition= "'$(CAD_Year)' &lt; '2010'">
    <ItemGroup>
      <Reference Include="AcRibbon">
        <HintPath>$(CAD_SDK_Location)\$(Inc)\AcRibbon.dll</HintPath>
        <Private>False</Private>
      </Reference>
    </ItemGroup>
  </When>
</Choose>

在这种情况下,仅当$(CAD_Year)小于2010时才引用AcRibbon. 为什么我得到不同的结果?

At this case the AcRibbon is referenced only when $(CAD_Year) less than 2010. Why I get the different results?

推荐答案

我在MSDN中找到了答案

I found the answer in MSDN here:

当条件导入语句在命令行MSBuild中工作时, 它们不适用于集成了Visual Studio的MSBuild 开发环境(IDE).有条件进口由 使用在以下情况下设置的配置和平台值 项目已加载.如果随后进行了更改,则需要 重新评估项目文件中的条件,例如, 更改平台后,Visual Studio会重新评估条件 属性和商品,但不包括进口商品.因为进口 不重新评估有条件的条件,将跳过导入.变通 这,将条件导入放在.targets文件中,或将代码放在 条件块,例如选择元素"(MSBuild)块.

While conditional import statements work in command-line MSBuilds, they do not work with MSBuild in the Visual Studio integrated development environment (IDE). Conditional imports are evaluated by using the configuration and platform values that are set when the project is loaded. If changes are subsequently made that require a reevaluation of the conditionals in the project file, for example, changing the platform, Visual Studio reevaluates the conditions on properties and items, but not on imports. Because the import conditional is not reevaluated, the import is skipped. To work around this, put conditional imports in the .targets files or put code in a conditional block such as a Choose Element (MSBuild) block.

我认为ItemGroup元素也是如此...

I think this is true for ItemGroup element also...

这篇关于为什么“条件"属性不适用于“元素组"元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆