使用afterbuild任务将整个项目结构复制到另一个目录 [英] Copying entire project structure into another directory using afterbuild task

查看:187
本文介绍了使用afterbuild任务将整个项目结构复制到另一个目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用AfterBuild目标将整个项目结构复制到一个单独的文件夹中.这是项目结构

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

我想将包括bin文件夹和.sln文件夹的整个项目结构复制到位置B:\animesh\repos.

为此,我将以下代码片段放入每个.csproj文件的AfterBuild目标中:

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

在构建项目时出现以下错误:

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

我在这里想念什么?


解决方案

根据AdrianMonk的回答,我这样更改了AfterBuild配置:

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

我将这个AfterBuild目标仅放在一个项目中,因为那样就足够了.

解决方案

您需要指定DestinationFolder,而不是DestinationFiles:

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

但是,这只会从项目结构的根目录复制文件.要复制整个结构,包括子目录中的文件,您需要使用:

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

这将对整个项目结构(还包括输出目录)进行递归复制.有关更多信息,请参考 MSBuild复制任务参考文档.

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.

解决方案

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.

这篇关于使用afterbuild任务将整个项目结构复制到另一个目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆