msbuild项目组项目

时间:2016-12-15 16:57:16

标签: batch-file msbuild msbuild-itemgroup

我有正在执行批处理文件的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

如何实现这一目标?

1 个答案:

答案 0 :(得分: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>       

相关问题