2016-12-15 126 views
0

我有執行批處理文件的msbuild文件。msbuild項目組項目

的MSBuild文件:

<PropertyGroup> 
    <ItemAString>Green;Red;Blue</ItemAString> 
    <ItemBString>Uno;Due;Tre</ItemBString> 
    <ItemCString>Song;Movie;Picture</ItemCString> 
</PropertyGroup> 

<ItemGroup> 
    <ItemsA Include="$(ItemAString.Split(';'))" /> 
    <ItemsB Include="$(ItemBString.Split(';'))" /> 
    <ItemsC Include="$(ItemCString.Split(';'))" /> 
</ItemGroup> 

<Target Name = "CallBatch">      
    <!-- THIS DOES NOT WORK --> 
    <Exec Command="mybatch.bat %(ItemsA.Identity) %(ItemsB.Identity) %(ItemsC.Identity)" />    
</Target>  

批處理文件非常簡單:

echo Params = [%1] - [%2] - [%3] 

我想下一個輸出:

Params = Green - Uno - Song 
Params = Red - Due - Movie 
Params = Blue - Movie - Picture 

如何實現ŧ他?

+0

如果那是正確的不知道,但你第一次訪問與'$',然後用''%變量。我沒有進入msbuild,但跳到我的眼睛。 – geisterfurz007

+1

搜索「跨產品」,答案應該在這裏的某個地方。示例:http://stackoverflow.com/questions/3893467/msbuild-batching-on-three-independent-variables/3893905#3893905或http://stackoverflow.com/questions/37186​​867/msbuild-merge-item-groups/ 37210038#37210038或... – stijn

回答

1

我找到了解決辦法:

<Project DefaultTarget="DoTheMagic" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="12.0"> 
<PropertyGroup Condition=" '$(TFP)'=='' "> 
    <TFP>$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll</TFP> 
    <TFP Condition=" !Exists('$(TFP)')">$(MSBuildFrameworkToolsPath)\Microsoft.Build.Tasks.v4.0.dll</TFP> 
    <TFP Condition=" !Exists('$(TFP)')">$(windir)\Microsoft.NET\Framework\v4.0.30319\Microsoft.Build.Tasks.v4.0.dll</TFP> 
</PropertyGroup> 

<UsingTask 
    TaskName="Bukake" 
    TaskFactory="CodeTaskFactory"  
    AssemblyFile="$(TFP)" > 
    <ParameterGroup> 
     <ItemsA Required="True" ParameterType="System.String"/> 
     <ItemsB Required="True" ParameterType="System.String"/> 
     <ItemsC Required="True" ParameterType="System.String"/> 
     <Result ParameterType="Microsoft.Build.Framework.ITaskItem[]" Output="True"/> 
    </ParameterGroup> 
    <Task>      
     <Code Type="Fragment" Language="cs"> 
      <![CDATA[ 
     string[] itemsA = ItemsA.Split(new char[] {';'}, StringSplitOptions.RemoveEmptyEntries); 
     string[] itemsB = ItemsB.Split(new char[] {';'}, StringSplitOptions.RemoveEmptyEntries); 
     string[] itemsC = ItemsC.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); 

     List<TaskItem> items = new List<TaskItem>(); 
     for (int index = 0; index < itemsA.Length; index++) 
     {        
      TaskItem item = new TaskItem(); 
      item.ItemSpec = "item"; 
      item.SetMetadata("itemA", itemsA[index]); 
      item.SetMetadata("itemB", itemsB[index]); 
      item.SetMetadata("itemC", itemsC[index]); 
      items.Add(item); 
     } 
     Result = items.ToArray();       
     ]]> 
     </Code> 
    </Task> 
</UsingTask> 

<PropertyGroup> 
    <ItemAString>Green;Red;Blue</ItemAString> 
    <ItemBString>Uno;Due;Tre</ItemBString> 
    <ItemCString>Song;Movie;Picture</ItemCString>  
</PropertyGroup> 

<Target Name = "CallBatch">  
    <Message Text="$(TFS)" /> 
    <Bukake ItemsA="$(ItemAString)" 
      ItemsB="$(ItemBString)" 
      ItemsC="$(ItemCString)"> 
     <Output TaskParameter="Result" ItemName="Dundonja" /> 
    </Bukake> 

    <ItemGroup>     
     <PreparedItems Include="@(Dundonja)"/>    
    </ItemGroup> 
    <!-- <Message Text="Dundonja: %(Dundonja.Identity) %(Dundonja.itemA) %(Dundonja.itemB) %(Dundonja.itemC)"/>   --> 
    <Exec Command="mybatch.bat Dundonja %(Dundonja.Identity) %(Dundonja.itemA) %(Dundonja.itemB) %(Dundonja.itemC)"/> 
</Target>