Msbuild根据目标参数列表复制到几个位置? [英] Msbuild copy to several locations based on list of destination parameter?

查看:168
本文介绍了Msbuild根据目标参数列表复制到几个位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个目录要复制到多个位置。

I got a directory I want to copy to a number of locations.

说我有


  • home.aspx

我想将其复制到


  • abc / home.aspx

  • def / home.aspx

  • ghi / home.aspx

  • abc/home.aspx
  • def/home.aspx
  • ghi/home.aspx

有两个问题:


  • 如何定义列表abc,def,ghi?

  • 如何用此列表的每个元素执行复制任务?

推荐答案

这是一个实际的例子,我放在一起,显示你在寻找什么:

Here is an actual example that I put together that shows what you were looking for:

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Test" ToolsVersion="3.5">

  <!--Declare an ItemGroup that points to your file you want to copy.-->
  <ItemGroup>
    <ItemToCopy Include=".\Home.aspx" />
  </ItemGroup>

  <!--Declare an ItemGroup that points to your destination Locations-->
  <ItemGroup>
    <DestLocations Include=".\abc\home.aspx" />
    <DestLocations Include=".\def\home.aspx" />
    <DestLocations Include=".\ghi\home.aspx" />
  </ItemGroup>

  <Target Name="CopyFiles">
    <!--Run the copy command to copy the item to your dest locations-->
    <!--This is where the magic happens.  The % sign before the DestLocations reference says to use
    Batching.  So Copy will be run for each unique FullPath MetaData in the DestLocations ItemGroup.-->
    <Copy SourceFiles="@(ItemToCopy)" DestinationFolder="%(DestLocations.FullPath)" />
  </Target>
</Project>

这篇关于Msbuild根据目标参数列表复制到几个位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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