I am setting up a dependency property group (to be used in a Target's DependsOnTargets attribute). I would like to have a dependency optionally show up depending on whether an item list exists and is non empty. So far, this is the best I could come up with:
<PropertyGroup>
<OtherLibFilesTemp>@(OtherLibFiles->'%(identity)')
</OtherLibFilesTemp>
<OtherLibTargets Condition="'$(OtherLibFilesTemp)' != ''">OtherLibTargets</OtherLibTargets>
<BuildLibDependsOn>
PrepareOutputDir;
CompileVcSource;
CompileMCppSource;
$(OtherLibTargets)
</BuildLibDependsOn>
</PropertyGroup>
Is there a way to do this without introducing the OtherLibFilesTemp node

Testing for empty item list in a condition
TheBlindBat
You can consider having an empty "Other" target in the main .targets file and then overriding it only in the leaf projects that need to redefine it. If you define multiple targets with the same name, the last one wins (obviously, it's important to put the leaf project target after the Import). This way you can have an extensible target in the dependency chain that doesn't do anything unless it's overriden in the leaf project.
thanks,
Lukasz
*jsd*
In our .targets files we usually put the "Other" target in the dependency chain and then put a condition on it, making it run only when the item list is not empty. Your target will not run (nor will any of its dependencies) if the condition evaluates to false. This should be equivalent to what you're trying to do.
Putting item lists inside conditions for properties is not usually what you want, since MSBuild evaluates all properties before evaluating item lists.
thanks,
Lukasz
taogeh
AH_OF
error MSB4057: The target "OtherLibTargets" does not exist in the project.
vasanthaprabu
knechod
<PropertyGroup>
<Other Condition="'@(OtherFiles)' != ''">Other</Other >
<BuildLibDependsOn>
PrepareOutputDir;
CompileVcSource;
CompileMCppSource;
$(Other)
</BuildLibDependsOn>
</PropertyGroup>
I get this error:
error MSB4099: A reference to an item list at position 2 is not allowed in this condition "'@(OtherFiles)' != ''".
Act_of_Bob