2010-06-15 4 views
15
<ItemGroup> 
    <!-- Unit Test Projects--> 
    <MyGroup Include="Hello.xml" /> 
    <MyGroup Include="GoodBye.xml" />  
</ItemGroup> 

이 목록을 반복하는 작업을 만들고 어떻게합니까?msbuild 배열 반복

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

myresult가 내부에 특정 텍스트가 있으면 오류 메시지를 표시하려고합니다. 그러나 내 인생에서 나는 Msbuild의 배열을 반복하는 방법을 알아낼 수 없다 ... 누구든지 이것을 수행하는 방법을 알고 있는가?

답변

17

당신은 그런 식으로, 내부 대상에 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> 
28

당신은 이것에 대한 일괄 처리를 사용해야합니다. 일괄 처리는 메타 데이터 키를 기반으로 일련의 항목을 반복합니다. 나는 이것에 대한 자료들을 함께 넣었습니다 http://sedotech.com/Resources#batching. 예를 들어이 간단한 MSBuild 파일을 살펴보십시오.

<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> 

당신이 데모 결과를 대상으로 구축

Not batched: one.txt;two.txt;three.txt;four.txt 
======================================== 
Batched: one.txt 
Batched: two.txt 
Batched: three.txt 
Batched: four.txt 

일괄 항상 구문 %(Xyz.Abc)을 사용합니다. 일괄 처리에 대한 자세한 정보는 해당 링크를 철저히 살펴보고 알고 싶었던 것입니다.

+0

항목 그룹의 첫 번째 항목을 얻으려면 어떻게해야합니까? 여러 가지 방법으로'[0]'과'First()'를 시도했지만 작동시키지 못했습니다. –