MS Visual Studio 2013.
Both When
and ItemGroup
elements can to have the Condition
attribute (as I see in MSDN). But I get different results.
When $(CAD_Year)
is 2015, I expect the AcRibbon
will be not referensed to my project:
<ItemGroup Condition= "'$(CAD_Year)' < '2010'" > <Reference Include="AcRibbon"> <HintPath>$(CAD_SDK_Location)\$(Inc)\AcRibbon.dll</HintPath> <Private>False</Private> </Reference> </ItemGroup>
But I get unresolved reference in the Solution Browser for the AcRibbon
always.
But this variant works fine:
<Choose> <When Condition= "'$(CAD_Year)' < '2010'"> <ItemGroup> <Reference Include="AcRibbon"> <HintPath>$(CAD_SDK_Location)\$(Inc)\AcRibbon.dll</HintPath> <Private>False</Private> </Reference> </ItemGroup> </When> </Choose>
At this case the AcRibbon
is referenced only when $(CAD_Year)
less than 2010. Why I get the different results?
In addition to the generic Item element, ItemGroup allows child elements that represent types of items, such as Reference , ProjectReference , Compile , and others as listed at Common MSBuild project items.
None - The file is not included in the project output group and is not compiled in the build process. An example is a text file that contains documentation, such as a Readme file. Compile - The file is compiled into the build output. This setting is used for code files.
I found the answer in 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.
I think this is true for ItemGroup
element also...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With