MSBuild recursive copy

我们两清 提交于 2019-12-13 00:39:33

问题


In Csproj I have the following section:

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

Thus if C\MyPath\ has a following structure:

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

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>

回答1:


Try MakeRelative property function:

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


来源:https://stackoverflow.com/questions/23806518/msbuild-recursive-copy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!