gpt4 book ai didi

msbuild - msbuild数组迭代

转载 作者:行者123 更新时间:2023-12-03 14:31:30 25 4
gpt4 key购买 nike

<ItemGroup>
<!-- Unit Test Projects-->
<MyGroup Include="Hello.xml" />
<MyGroup Include="GoodBye.xml" />
</ItemGroup>


我如何做遍历此列表并执行某些操作的任务?

<XmlPeek XmlInputPath="%(MyGroup.Identity)"
Query="/results">
<Output TaskParameter="Result"
ItemName="myResult" />
</XmlPeek>


如果myresult里面有特定文本,我想发出一条错误消息。但是对于我一生,我无法弄清楚如何在Msbuild中遍历数组……任何人都知道如何实现这一点?

最佳答案

您可以在内部目标上使用batching,例如:

<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 - msbuild数组迭代,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3045821/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com