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

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

问题描述

微软 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...

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

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