You need to use batching for this. Batching will iterate over a set of items based on a metadata key. I've put together a bunch of material on this at http://sedotech.com/Resources#batching. For example take a look at this simple MSBuild file.
<Project DefaultTargets="Demo" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Files Include="one.txt"/>
<Files Include="two.txt"/>
<Files Include="three.txt"/>
<Files Include="four.txt"/>
</ItemGroup>
<Target Name="Demo">
<Message Text="Not batched: @(Files->'%(Identity)')"/>
<Message Text="========================================"/>
<Message Text="Batched: %(Files.Identity)"/>
</Target>
</Project>
When you build the Demo target the results are
Not batched: one.txt;two.txt;three.txt;four.txt
========================================
Batched: one.txt
Batched: two.txt
Batched: three.txt
Batched: four.txt
Batching always uses the syntax %(Xyz.Abc)
. Take a look thorough those links for more info about batching then you ever wanted to know.
You could use batching on an inner target, like that :
<ItemGroup>
<!-- Unit Test Projects-->
<MyGroup Include="Hello.xml" />
<MyGroup Include="GoodBye.xml" />
</ItemGroup>
<Target Name="CheckAllXmlFile">
<!-- Call CheckOneXmlFile foreach file in MyGroup -->
<MSBuild Projects="$(MSBuildProjectFile)"
Properties="CurrentXmlFile=%(MyGroup.Identity)"
Targets="CheckOneXmlFile">
</MSBuild>
</Target>
<!-- This target checks the current analyzed file $(CurrentXmlFile) -->
<Target Name="CheckOneXmlFile">
<XmlPeek XmlInputPath="$(CurrentXmlFile)"
Query="/results/text()">
<Output TaskParameter="Result" ItemName="myResult" />
</XmlPeek>
<!-- Throw an error message if Result has a certain text : ERROR -->
<Error Condition="'$(Result)' == 'ERROR'"
Text="Error with results $(Result)"/>
</Target>