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

Why the `Condition` attribute doesn't work for the `ItemGroup` element?

MS 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>

但我总是在 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>

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

我在 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 元素也是如此...