Copying entire project structure into another directory using afterbuild task

我是研究僧i 提交于 2020-01-06 18:37:12

问题


I want to use the AfterBuild target for copying the entire project structure into a separate folder. This is the project structure

TANKProject  
|
|__TANK.CLI
|__TANK.Core
|__TANK.Web 

I want to copy the entire project structure including bin folder and the .sln folder into a location B:\animesh\repos.

To do that, I put the following snippet in the AfterBuild target in each .csproj file:

<ItemGroup>
    <_CustomFiles Include="..\TANK.ProjectName\*.*" />
</ItemGroup>
<Copy
    SourceFiles="@(_CustomFiles)"
    DestinationFiles="B:\repos\TANK"
    SkipUnchangedFiles="true" />

I get the following error while building the project:

"DestinationFiles" refers to 3 item(s), and "SourceFiles" refers to 1 item(s). They must have the same number of items.

What am I missing here?


Solution

Based on AdrianMonk's answer, I changed my AfterBuild configuration like this:

  <Target Name="AfterBuild">
    <ItemGroup>
      <_CustomFiles Include="..\**" />
    </ItemGroup>
    <Copy 
      SourceFiles="@(_CustomFiles)" 
      DestinationFiles="@(_CustomFiles->'B:\repos\TANK\%(RecursiveDir)%(Filename)%(Extension)')" 
      SkipUnchangedFiles="true" />
  </Target>

I put this AfterBuild target in only one of the projects since that would be sufficient.


回答1:


You need to specify DestinationFolder, not DestinationFiles:

<Copy
    SourceFiles="@(_CustomFiles)"
    DestinationFolder="B:\repos\TANK"
    SkipUnchangedFiles="true" />

However, this will only copy the files from the root of you project structure. To copy the whole structure including files in subdirectories, you need to use:

<Copy
    SourceFiles="@(_CustomFiles)"
    DestinationFiles="@(_CustomFiles->'B:\repos\TANK\%(RecursiveDir)%(Filename)%(Extension)')"
    SkipUnchangedFiles="true" />

This will do a recursive copy of the entire project structure (also including the output directories). For more information, refer to the MSBuild Copy task reference docs.



来源:https://stackoverflow.com/questions/15326113/copying-entire-project-structure-into-another-directory-using-afterbuild-task

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!