msbuild数组迭代 [英] msbuild array iteration
本文介绍了msbuild数组迭代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<ItemGroup>
<!-- Unit Test Projects-->
<MyGroup Include="Hello.xml" />
<MyGroup Include="GoodBye.xml" />
</ItemGroup>
我该如何遍历此列表并执行某项任务?
How do I make a task that iterates through this list and does something?
<XmlPeek XmlInputPath="%(MyGroup.Identity)"
Query="/results">
<Output TaskParameter="Result"
ItemName="myResult" />
</XmlPeek>
如果myresult中包含特定文本,我想显示一条错误消息.但是对于我一生来说,我无法弄清楚如何在Msbuild中遍历数组……任何人都知道如何完成此工作?
I want to thow an error message if myresult has a certain text inside of it. However for the life of me I can't figure out how to iterate through arrays in Msbuild... anyone know how to accomplish this?
推荐答案
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>
这篇关于msbuild数组迭代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文