MSBuild 任务通过在路径中使用通配符来复制特定文件夹的内容

MSBuild task to Copy contents of a specific folder by using a wild card in the path

我的文件夹结构如下

Module
-->Asia - 1.0.0.12
------>Deployment
------>Install.exe
------>version.xml
-->Africa - 1.0.3.4
------>Deployment
------>Install.exe
------>version.xml
-->Europe - 2.0.1.2
------>Deployment
------>Install.exe
------>version.xml

我想将每个区域下的'deployment'文件夹(和子文件夹)复制到我的输出目录。区域编号将更改,因此我不能在我的 Include 语句中对它们进行硬编码。我用来为亚洲地区复制的命令是

    <ItemGroup>
        <GetFiles Include="$(MSBuildProjectDirectory)\Module\Asia*\Deployment\**\*">
            <Destination>D:\Region\Asia</Destination>
        </GetFiles >
    </ItemGroup>
    <Copy
        SourceFiles="%(GetFiles.Identity)"
        DestinationFolder="%(GetFiles.Destination)\%(RecursiveDir)"
    />

我没有将 Deployment 文件夹及其子目录复制到 Destination 下,而是将文件夹结构设为

D:\Region\Asia\Asia - 1.0.0.12\Deployment

我想要的是

D:\Region\Asia\Deployment

这能实现吗?谢谢

MSBuild task to Copy contents of a specific folder by using a wild card in the path

如果在msbuild中使用了通配符,并且做复制任务,MSBuild会一直从使用通配符的第一个地址开始复制路径。

对于您的情况,由于您只是在 Asia* 下使用通配符,因此它将在 D:\Region\Asia.

下保留 Asia - 1.0.0.12\Deployment 文件夹结构

作为建议,为了得到你想要的,你需要明确指出Asia文件夹的名称,即使它比较复杂,需要一一说明。

这样使用:

    <Target Name="xxx" BeforeTargets="Build">
      <ItemGroup>
            <GetFiles Include="$(MSBuildProjectDirectory)\Module\Asia - 1.0.0.12\Deployment\**\*">
                <Destination>D:\Region\Asia</Destination>
            </GetFiles>
     </ItemGroup>
     <Copy SourceFiles="%(GetFiles.Identity)"
           DestinationFolder="%(GetFiles.Destination)\Deployment\%(RecursiveDir)"/>
    
   </Target>