MSBuild递归复制 [英] MSBuild recursive copy

查看:475
本文介绍了MSBuild递归复制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Csproj我有以下部分:

In Csproj I have the following section:

<ItemGroup>
    <Content Include="C\MyPath\**">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <Link>Res\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </Content>

因此,如果C\MyPath \具有以下结构:

Thus if C\MyPath\ has a following structure:

-C
 -MyPath
  -f1.txt
  -folder1
   -f3.txt
   -folder4
  -folder2
   -f4.txt
   -folder5

我不想要完全递归复制
,但我想要folder1和folder2不生成
,而是从第二级开始递归复制:

I don`t want exactly the recursive copy but I want folder1 and folder2 not to be generated but rather start recursive copy from the second level:

-Res
 - f1.txt
 - f3,txt
 - folder4
 - f4.txt
 - folder5

如何分别从每个文件夹复制:

How can I do it without copying from each folder separately:

 <Content Include="C\MyPath\folder1\**">
              <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
              <Link>Res\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </Content>
<Content Include="C\MyPath\folder2\**">
              <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
              <Link>Res\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </Content>


推荐答案

尝试 MakeRelative 属性函数

Try MakeRelative property function:

<Copy SourceFiles="@(Content)"
          DestinationFolder="Res\$([MSBuild]::MakeRelative(%(Content.RelativeDir), %(Content.Filename)))" />

这篇关于MSBuild递归复制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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