MSBuild在路径名中使用元数据时复制整个目录 [英] MSBuild copy entire directory while using metadata in path names

查看:340
本文介绍了MSBuild在路径名中使用元数据时复制整个目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里有几个我发现的类似答案,但没有答案我的问题:

Here are few other similar answers that I've found, but none answers my question:

使用afterbuild任务将整个项目结构复制到另一个目录

使用msbuild复制所有文件和文件夹

MSbuild复制整个文件夹

我要做什么:

我需要在编译时将目录树复制到项目中的几个不同位置。
以下是目前的操作方式:

I need to copy a directory tree into several different places in the project upon compilation. Here is how it presently being done:

  <ItemGroup>
    <MediaFiles Include="$(ProjectDir)media\**\*.*" />
    <DeployLabel Include="$(ProjectDir)deploy\x">
      <Dir>x</Dir>
    </DeployLabel>
    <DeployLabel Include="$(ProjectDir)deploy\y">
      <Dir>y</Dir>
    </DeployLabel>
    <DeployLabel Include="$(ProjectDir)deploy\z">
      <Dir>z</Dir>
    </DeployLabel>
  </ItemGroup>
  <Target Name="GenericDeploy"
          Inputs="@(DeployLabel)"
          Outputs="%(Identity).Dummy">
    <Message Text="Deploying: @(DeployLabel)" />
    <Copy SourceFiles="@(MediaFiles)"
          DestinationFiles="@(MediaFiles->'$(ProjectDir)deploy%(Dir)media\%(RecursiveDir)%(Filename)%(Extension)')"/>

这假装运行,但什么都不复制。我也尝试使用%(DeployLabel.Dir),但是给我一个错误。

This pretends to run, but copies nothing at all. I've tried also to use %(DeployLabel.Dir), but that gives me an error.

不想使用 xcopy ,因为此程序似乎不在Windows安装的默认清单(我的电脑没有)。此外,我必须承认,我不完全明白东西做什么。当我第一次看到@和%,我认为他们从Make复制,但现在我开始怀疑...还有一些洞察什么 - > 意味着帮助(很难找到关于这些隐含名称的文档)。

I don't want to use xcopy because this program doesn't seem to be in the default inventory of Windows installs (my PC doesn't have it). Also, I must confess, I don't entirely understand what does the % thingy do. When I saw @ and % at first, I thought they were copied from Make, but now I' starting to doubt... Also some insight into what -> means would help (it's extremely difficult to find the documentation on these cryptic names).

推荐答案

这些批处理很混乱,批处理使用不同的ItemGroups,一些不是。我创建一个小项目以显示一些差异:

These batchings are quite confusing, because some combinations of batchings are working with different ItemGroups and some not. I create a small proj to show some differences:

<?xml version="1.0" encoding="utf-8"?> 
<Project DefaultTargets="Batch" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
 <ItemGroup>
  <BatchItem Include="myFile.txt">
   <Folder>c:\Temp</Folder>
  </BatchItem>
  <BatchItem Include="myFile2.txt">
   <Folder>c:\Tmp</Folder>
  </BatchItem>

  <DifferentItem Include="myFile3.txt">
   <Folder>c:\diff</Folder>
  </DifferentItem>
 </ItemGroup>

 <Target Name="Batch">
  <Message Text="Using (at) @(BatchItem) --  @(DifferentItem)" />
  <Message Text="Using -> @(BatchItem->'%(Folder)\somethingInbetween\%(Identity)') -- @(DifferentItem->'%(Folder)\somethingInbetween\%(Identity)')" />   
  <Message Text="Using percent %(BatchItem.Folder)\%(BatchItem.Identity) -- %(DifferentItem.Folder)\%(DifferentItem.Identity)" />
 </Target>
</Project>




  • 第一个将所有后面的项目放在字符串分号分隔

  • 第二个将使用一个项目的特定元数据来创建它的字符串。

  • 第三个表达式也引用了一个项目的元数据,但它也调用了每个元素的目标项目。

    • The first one will just put all after items in on string semicolon separated.
    • The second one will use specific metadata of one item to make a string of it. This is done for all elements and they are semicolon separated as one item.
    • The third expression is also referencing the metadata of an item, but it is also calling the target for each item in the group. Doing it that way you can't mix ItemGroups.

      使用(at)myFile.txt; myFile2.txt - myFile3.txt

      Using (at) myFile.txt;myFile2.txt -- myFile3.txt

      使用 - > c:\Temp\somethingInbetween\myFile.txt; c:\Tmp\somethingInbetween\myFi
      le2.txt - c:\diff\\ \\ somethingInbetween\myFile3.txt

      Using -> c:\Temp\somethingInbetween\myFile.txt;c:\Tmp\somethingInbetween\myFi le2.txt -- c:\diff\somethingInbetween\myFile3.txt

      使用百分比c:\Temp\myFile.txt - \

      Using percent c:\Temp\myFile.txt -- \

      使用百分比c:\Tmp\myFile2.txt - \

      Using percent c:\Tmp\myFile2.txt -- \

      使用百分比\ - c:\diff\myFile3.txt

      Using percent \ -- c:\diff\myFile3.txt

      这篇关于MSBuild在路径名中使用元数据时复制整个目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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