为什么“条件"属性不适用于“元素组"元素?

编程入门 行业动态 更新时间:2024-10-13 08:26:16
本文介绍了为什么“条件"属性不适用于“元素组"元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

MS Visual Studio 2013.

MS Visual Studio 2013.

When和ItemGroup元素都可以具有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...

更多推荐

为什么“条件"属性不适用于“元素组"元素?

本文发布于:2023-10-26 17:42:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1530875.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:元素   属性   不适用于   条件   quot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!