我试图多次使用列表中的项目。该列表是使用MSBuild扩展名从目录名称创建的:
<MSBuild.ExtensionPack.FileSystem.FindUnder TaskAction="FindDirectories" Recursive="false" Path="path\to\stuff\">
<Output ItemName="AllFoundDirectories" TaskParameter="FoundItems"/>
</MSBuild.ExtensionPack.FileSystem.FindUnder>
我希望在不同的情况下使用此列表中的每个项目,例如:
<Message Text="##teamcity[testStarted name='%(AllFoundDirectories.FileName)']"/>
<!-- do some stuff using %(AllFoundDirectories.FileName) here -->
<Message Text="##teamcity[testFinished name='%(AllFoundDirectories.FileName)' duration='test_duration_in_milliseconds']"/>
我遇到的问题是,MSBuild第一次看到列表中的所有内容都是变量%(AllFoundDirectories.FileName)。有没有办法一次从列表中获取单个变量并在各个地方使用它?
答案 0 :(得分:2)
在依赖目标上使用目标批处理。
<Target Name="MakeDirectoryItems">
<MSBuild.ExtensionPack.FileSystem.FindUnder
TaskAction="FindDirectories"
Recursive="false" Path="path\to\stuff\">
<Output
ItemName="AllFoundDirectories"
TaskParameter="FoundItems"
/>
</MSBuild.ExtensionPack.FileSystem.FindUnder>
</Target>
<Target Name="UseDirectoryItemsInBatch"
Outputs="%(AllFoundDirectories.Identity)">
<!--
while inside this target, the value of both @(AllFoundDirectories)
and %(AllFoundDirectories.Meta) will be just the single item
in each batch.
-->
</Target>
<Target Name="Driver"
DependsOnTargets="MakeDirectoryItems;UseDirectoryItemsInBatch">
</Target>