MSBuild recursive copy

2019-08-10 10:52发布

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条回答
SAY GOODBYE
2楼-- · 2019-08-10 11:27

Try MakeRelative property function:

<Copy SourceFiles="@(Content)"
          DestinationFolder="Res\$([MSBuild]::MakeRelative(%(Content.RelativeDir), %(Content.Filename)))" />
查看更多
登录 后发表回答