Why doesn't MSBuild copy as I would expect

后端 未结 4 2245
忘掉有多难
忘掉有多难 2021-02-09 10:20

I\'m needing to script my build. I\'m using MSBUILD because of it\'s integration with VS.net. I am trying to copy some files from the build environment to the deployment folder

4条回答
  •  死守一世寂寞
    2021-02-09 10:37

    When you specify the DestinationFolder for the Copy task, it takes all items from the SourceFiles collection and copies them to the DestinationFolder. This is expected, as there is no way for the Copy task to figure out what part of each item's path needs to be replaced with the DestinationFolder in order to keep the tree structure. For example, if your SourceDir collection is defined like this:

    
        
        
        
    
    

    What would you expect the destination folder tree look like?

    To preserve the tree, you need to do identity transformation and generate one destination item for each item in the SourceFiles collection. Here's an example:

    
    

    The Copy task will take the each item in the SourceFiles collection, and will transform its path by replacing the part before the ** in the source item specification with $(DropPath).

    One could argue that the DestinationFolder property should have been written as a shortcut to the following transformation:

    
    

    Alas, that would prevent the deep copy to flat folder scenario that you are trying to avoid, but other people might using in their build process.

提交回复
热议问题