2014-01-30 59 views
0

我有安裝的的ItemGroup,每一個包含這樣的屬性,它是從輸出文件夾(分隔)的名稱:的MSBuild樞轉的ItemGroup上分隔字符串

<ItemGroup> 
    <Installers Include="Installer1.msi"> 
    <Folders>Folder1,Folder4</Folders> 
    </Installers> 

    <Installers Include="Installer2.msi"> 
    <Folders>Folder1,Folder2,Folder3,Folder4</Folders> 
    </Installers> 
</ItemGroup> 

我希望能夠複製每個安裝程序放入指定的每個文件夾中。我已經來回試圖找出一種方法來額外的元數據添加到安裝程序,但似乎無法得到的是這樣的一個最後的名單:

  1. Installer1.msi:Folder1中
  2. Installer1.msi:Folder4
  3. Installer2.msi:Folder1中
  4. Installer2.msi:文件夾2
  5. Installer2.msi:Folder3
  6. Installer2.msi:Folder4

所以我可以執行這樣的事情:

<Copy SourceFiles="@(Installers)" DestinationFolder="%(Installers.Folder)" /> 

我知道我可以修改我的ItemGroup這樣:

<ItemGroup> 
    <Installers Include="Installer1.msi"> 
    <Folder>Folder1</Folder> 
    </Installers> 
    <Installers Include="Installer1.msi"> 
    <Folder>Folder4</Folder> 
    </Installers> 

    <Installers Include="Installer2.msi"> 
    <Folder>Folder1</Folder> 
    </Installers> 
    <Installers Include="Installer2.msi"> 
    <Folder>Folder2</Folder> 
    </Installers> 
    <Installers Include="Installer2.msi"> 
    <Folder>Folder3</Folder> 
    </Installers> 
    <Installers Include="Installer2.msi"> 
    <Folder>Folder4</Folder> 
    </Installers> 
</ItemGroup> 

,但我寧願不要,因爲這就是我們現在的人有總是想念事情(因爲它非常冗長)。

+0

我猜測對方的要求,我想,是我像這樣爲N文件夾工作。例如。我不想先知道我的文件夾名稱,我更願意發現它們,因爲它們位於「文件夾」屬性中。 –

回答

0

用分號分隔的文件夾名稱,然後反安裝程序和文件夾的值:

<Project ToolsVersion="4.0" DefaultTargets="Inversionator" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 
    <ItemGroup> 
     <Folders Include="Folder1;Folder4"> 
      <Installer>Installer1.msi</Installer> 
     </Folders> 
     <Folders Include="Folder1;Folder2;Folder3;Folder4"> 
      <Installer>Installer2.msi</Installer> 
     </Folders> 
    </ItemGroup> 

    <Target Name="Inversionator"> 
     <Message Text="%(Folders.Installer) %(Folders.Identity) " Importance="high" /> 
    </Target> 
</Project> 

輸出爲現在的任務是:

Installer1.msi Folder1 
Installer1.msi Folder4 
Installer2.msi Folder1 
Installer2.msi Folder2 
Installer2.msi Folder3 
Installer2.msi Folder4 
+0

對不起,接受遲到。我花了一段時間思考,如果這能滿足我所有的審美要求並經過反思,確定它的確如此! –