gpt4 book ai didi

visual-studio - 为什么 `Condition` 属性对 `ItemGroup` 元素不起作用?

转载 作者:行者123 更新时间:2023-12-03 20:28:39 25 4
gpt4 key购买 nike

微软 Visual Studio 2013。

两个WhenItemGroup元素可以有Condition属性(正如我在 MSDN 中看到的)。但我得到不同的结果。

$(CAD_Year)是 2015 年,我预计 AcRibbon将是 不是 引用我的项目:

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

但是我在解决方案浏览器中得到 Unresolved reference AcRibbon总是。

但是这个变体工作正常:
<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>

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

最佳答案

我在 MSDN here 中找到了答案:

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 是这样的。元素也...

关于visual-studio - 为什么 `Condition` 属性对 `ItemGroup` 元素不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28851338/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com