How can I use MSBuild Copy Task to Copy To Multiple Destination Folders?

前端 未结 2 1364
伪装坚强ぢ
伪装坚强ぢ 2021-02-02 14:18

I\'m trying to copy a folder recursively to multiple destination folders using MSBuild\'s Copy task. I\'ve seen the following question which gave me a good sta

2条回答
  •  星月不相逢
    2021-02-02 15:12

    What you are dealing with here is known as batching. I have blogged quite a bit about batching. You can find my blogs listed at http://sedotech.com/Resources#Batching. Batching is a way to do a loop without really doing one in MSBuild. You can split groups into values with a common metadata value. Metadata could be values like Identity, FullPath, Filename, etc. You can even make your own metadata. In any case when you batch on more than 1 value they are batched independently of each other. Take a look at the example that I created. The result of executing the target is shown after the script.

    
    
      
        
      
    
      
        
        
      
    
      
      
        
    
        
        
        
        
        
        
        
        
          <_DeployPathIdentity>%(DeployPath.Identity)
        
        
    
        
        
      
    
    
    

    Output

    Build started 9/10/2010 9:31:28 PM.
    Project "I:\Development\My Code\Community\MSBuild\CopyFiles01.proj" on node 1 (default targets).
    Demo:
      DeployPath.Identity: C:\temp\path01\
      ======================================
      ItemsToCopy1: src\0001.txt;src\0002.txt;src\sub\sub-0001.txt;src\sub\sub-0002.txt|| DeployPath.I
      dentity: C:\temp\path01\
      ======================================
      ItemsToCopy2: || DeployPath.Identity-RecursiveDir: C:\temp\path01\\
      ItemsToCopy2: src\0001.txt;src\0002.txt;src\sub\sub-0001.txt;src\sub\sub-0002.txt|| DeployPath.I
      dentity-RecursiveDir: \
      ======================================
      ItemsToCopy3: src\0001.txt;src\0002.txt;src\sub\sub-0001.txt;src\sub\sub-0002.txt|| _DeployPathI
      dentity-RecursiveDir: C:\temp\path01\\
      Creating directory "C:\temp\path01".
      Copying file from "src\0001.txt" to "C:\temp\path01\0001.txt".
      Copying file from "src\0002.txt" to "C:\temp\path01\0002.txt".
      Copying file from "src\sub\sub-0001.txt" to "C:\temp\path01\sub-0001.txt".
      Copying file from "src\sub\sub-0002.txt" to "C:\temp\path01\sub-0002.txt".
    Demo:
      DeployPath.Identity: C:\temp\path02\
      ======================================
      ItemsToCopy1: src\0001.txt;src\0002.txt;src\sub\sub-0001.txt;src\sub\sub-0002.txt|| DeployPath.I
      dentity: C:\temp\path02\
      ======================================
      ItemsToCopy2: || DeployPath.Identity-RecursiveDir: C:\temp\path02\\
      ItemsToCopy2: src\0001.txt;src\0002.txt;src\sub\sub-0001.txt;src\sub\sub-0002.txt|| DeployPath.I
      dentity-RecursiveDir: \
      ======================================
      ItemsToCopy3: src\0001.txt;src\0002.txt;src\sub\sub-0001.txt;src\sub\sub-0002.txt|| _DeployPathI
      dentity-RecursiveDir: C:\temp\path02\\
      Creating directory "C:\temp\path02".
      Copying file from "src\0001.txt" to "C:\temp\path02\0001.txt".
      Copying file from "src\0002.txt" to "C:\temp\path02\0002.txt".
      Copying file from "src\sub\sub-0001.txt" to "C:\temp\path02\sub-0001.txt".
      Copying file from "src\sub\sub-0002.txt" to "C:\temp\path02\sub-0002.txt".
    Done Building Project "I:\Development\My Code\Community\MSBuild\CopyFiles01.proj" (default targets
    ).
    
    
    Build succeeded.
    

提交回复
热议问题