MSBuild - recursive move/copy filed under a directory to the destination folder

It is a very common use case to copy files under one directory to another but keep the structure of the files copied.


You can do with some external command such as xcopy and wrap it in a task in MSBuild, however, MSBulid does porvide some built-in task for copying and moving files.  See theMSBuild Built-in tasks here 

As discussed in this post: How to : recursively Copy Files Using the Task.


We know we can use something like this: 


       
   

This is a new way of using the MSBuild task/target.. the syntax above basically instruct to expand and execute the command once for each of the elements in the Compile item group. This is part of advanced MSBuild concept, which is called MSBuild Batching.. In this special case, it is using the Task Batching....


A more traditional way is like this: 

 

    

    

    

    

    

 




The key to the solution is the special use of the MSBuild Items, the % notation start something which is called the Metadata of the Item, and the syntax of 

@(SourceFiles->'$(EXECUTABLES_ROOT)$(FolderName)\$(BuildLevel)\%(RecursiveDir)%(Filename)%(Extension)')


Is called the transforms of MSBuild item.  See Transforming Item Types By Using Metadata. and See more about the MSbuild Items.

I happen to do some task of moving files from one directory to another, please see my code below. 

  
    
      $(OutDir)..\..\.debug\$(FrameworkSpecializedFolder)
    
    
      
    
    
    
    
    
    
  





你可能感兴趣的:(msbuild)