msbuild 数组迭代 [英] msbuild array iteration

查看:15
本文介绍了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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆