I have my own build rule in VS2010 for my VC ++ project. In this rule, I would like to allow users to add complex conditions as to whether the file is being processed.
It also needs to be evaluated at the time of the target execution, and not in the “state” of the “element” itself (due to the fact that only the “application” project can process it and must process it by setting the project “application” rather than dependent projects )
I tried adding a custom field to the object, and then just removing the elements from the group at runtime. eg.
<ItemGroup>
<MyItemType Remove="@(MyItemType)" Condition="!(%(MyItemType.IncludeCondition))" />
</ItemGroup>
Unfortunately this gives me an error:
error MSB4113: specified condition "! (% (MyItemType.IncludeCondition))" evaluates to "!" testfilename1 '==' testfilename2 'or false "instead of boolean.
(The original condition expression in '% (MyItemType.IncludeCondition)' was '%(Filename)' == 'testfilename2' or $(TestBooleanFalse))
It seems that MSBuild will not evaluate the content of the metadata of the element in a logical way (this seems like good practice in most cases, and not this one).
In any case, can I get MSbuild to really evaluate the metadata to a boolean, or is there some other method that I could use to get the same result?
PS I looked briefly at MSBuild Property Functions , but could not see anything that could run the MSBuild logical evaluation code through function input)
MSBuild, , Lanrokin:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
<ItemGroup>
<MyItemType Include="item1.ext1" />
<MyItemType Include="item1.ext2" />
</ItemGroup>
<Target Name="SpecifyConditions">
<ItemGroup>
<MyItemType>
<IncludeCondition>'%(Filename)%(Extension)' == 'item1.ext1'</IncludeCondition>
</MyItemType>
</ItemGroup>
</Target>
<Target Name="Build" DependsOnTargets="SpecifyConditions">
<Message Importance="high" Text="@(MyItemType)" Condition="%(MyItemType.IncludeCondition)" />
</Target>
</Project>