构建脚本以将文件从各种源文件夹复制到各种目标文件夹 [英] Build script to copy files from various source folder to various destination folder

查看:133
本文介绍了构建脚本以将文件从各种源文件夹复制到各种目标文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本要求是将不同解决方案/项目目录中的各种文件和文件夹复制到单个build_output文件夹(/子文件夹)中.

The basic requirement is to copy the various files and folders from different solution/project directories to the single build_output folder(/subfolders).

当前,我正在使用 Robocopy 命令执行此操作.唯一的问题是我的脚本太长了,仅使用多个Robocopy命令即可.

Currently, I am doing this operation using the Robocopy commands. The only issue is my script is too long just using multiple Robocopy commands.

<Copy SourceFiles="$(Docs)\Manual.pdf" DestinationFolder="$(BuildPath)\Help"/>
<RoboCopy Source="$(Web1)" Destination="$(BuildPath)" Files="*.aspx" Options="/E"/>
<RoboCopy Source="$(Web1)\Images" Destination="$(BuildPath)\Images" Files="*.jpg;*.png" Options="/E"/>
<RoboCopy Source="$(Web2)\Images" Destination="$(BuildPath)\Images" Files="*.jpg;*.png" Options="/E"/>
<!--- 100s of such RoboCopy & Copy commands (note that in last two commands i need to copy from different sources to same destination -->

  1. 如何在实际的企业应用程序中实施此工作,以便 构建脚本简洁明了.
  2. 我下面的想法是解决问题的方法.如果是的话,有人可以使用MSBuild或CommandScript轻松地为我提供示例步骤. (免费使用任何MSBuild扩展)
    • 定义所有源文件夹,文件类型(可以是xyz.png/ .png/.*)和目标路径的映射.
    • 使用单个目标或任务使用上述映射复制文件(自动复制)
  1. How this job is implemented in real enterprise applications, so that the build script is concise and clear.
  2. Is my thinking below is the way to approach the solution. If yes, can anybody provide me sample steps using MSBuild or CommandScript easily. (free to use any MSBuild extensions)
    • Define the mapping of the all source folders, file types (can be xyz.png/.png/.*) and the destination path.
    • Copy the files (Robocopy) using the above mentioned mappings using a single target or task)

见解/解决方案

推荐答案

我恰好做了这种事情来分阶段构建输出,以供安装程序构建使用.我有一个自定义目标文件以进行一致的处理,还有一些msbuild属性文件,其中包含需要完成的项目组.

I do exactly this sort of thing to stage build output for harvesting by the installer build. I have a custom targets file for consistent processing and have some msbuild property files with the item groups describing that needs to be done.

  <ItemGroup Label="AcmeComponent1Payload">
    <FileToHarvest Include="$(SourceRoot)AcmeProjects\ServerManager\$(Configuration)\**\*;
                            $(SourceRoot)Library\SQLServerCompact\**\*;
                            $(SourceRoot)Utility Projects\PropertyDataValidator\PropertyDataValidator\bin\$(Configuration)\PropertyDataValidator.*"
                   Exclude="$(SourceRoot)Server Manager Projects\AcmeServerManager\$(Configuration)\IntegrationTests.*;
                            $(SourceRoot)Server Manager Projects\AcmeServerManager\$(Configuration)\**\Microsoft.Practices.*.xml;
                            $(SourceRoot)Server Manager Projects\AcmeServerManager\$(Configuration)\obj\**\*;
                            $(SourceRoot)Server Manager Projects\AcmeServerManager\$(Configuration)\**\Microsoft.VisualStudio.*;
                            $(SourceRoot)Server Manager Projects\AcmeServerManager\$(Configuration)\**\Microsoft.Web.*;
                            $(SourceRoot)Utility Projects\PropertyDataValidator\PropertyDataValidator\bin\$(Configuration)\PropertyDataValidator.xml">
      <Group>AcmeServerManager</Group>
      <SubDir>Utilities\</SubDir>
    </FileToHarvest>
  </ItemGroup>

自定义目标文件具有处理该文件的功能.

The custom targets file has the functionality to process it.

  <Target Name="CopyFiles">
    <Copy Condition="@(FileToHarvest)!=''"
          SourceFiles="@(FileToHarvest)"
          DestinationFiles="@(FileToHarvest->'$(OutputPath)\%(Group)\%(SubDir)%(RecursiveDir)%(Filename)%(Extension)')"
          OverwriteReadOnlyFiles="true"
          SkipUnchangedFiles="true" />
  </Target>

您可以根据需要使属性文件简单或复杂.我使用多个,然后使用通配符将它们导入到项目文件中.

You can make the properties file as simple or as complicated as you like. I use multiple ones and import them into the project file using wildcards.

这篇关于构建脚本以将文件从各种源文件夹复制到各种目标文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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