从msbuild中的多个目录复制文件
Copying files from multiple directories in msbuild
我有以下目录(例如)
./dirA/file1
./dirA/dir/file2
./dirB/file3
./dirB/dir/file4
./dirC/file5
我想将它们复制到不同的地方,例如:
./dirA_renamed/file1
./dirA_renamed/dir/file2
./dirB_renamed_differently/file3
./dirB_renamed_differently/dir/file4
./dirC_renam/file5
目录列表及其新名称不会经常更改,但我只想使用一个 Copy
。
我试过以下方法:
<ItemGroup>
<ToCopy Include=".\dirA">
<OutputDirName>dirA_renamed</OutputDirName>
</ToCopy>
<ToCopy Include=".\dirB">
<OutputDirName>dirB_renamed_differently</OutputDirName>
</ToCopy>
<ToCopy Include=".\dirC">
<OutputDirName>dirC_renam</OutputDirName>
</ToCopy>
</ItemGroup>
......
<CreateItem Include="%(ToCopy.Directory)\**\*.*">
<Output TaskParameter="Include" ItemName="FilesToCopy" />
</CreateItem>
<Copy SourceFiles="@(FilesToCopy)" DestinationFolder="@(FilesToCopy->'%(OutputDirName)')" />
但是没有任何反应。如果我输出FilesToCopy
,它是空的。我做错了什么?
硬编码方式是我知道的方式,但我知道你可以使用参数,我只是还没有完全弄明白,给你一个工作示例。
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
ToolsVersion="4.0" DefaultTargets="Build">
<PropertyGroup>
<RootDir>C:\DevDir</RootDir>
<SourceA>dirA</SourceA>
<SourceB>dirB</SourceB>
<SourceC>dirC</SourceC>
<RenameA>dirA_renamed</RenameA>
<RenameB>dirB_renamed_differently</RenameB>
<RenameC>dirC_renam</RenameC>
</PropertyGroup>
<Target Name="CopyDirTest" >
<ItemGroup>
<SourceDirA Include="$(RootDir)$(SourceA)\"/>
<SourceDirB Include="$(RootDir)$(SourceB)\" />
<SourceDirC Include="$(RootDir)$(SourceC)\" />
</ItemGroup>
<ItemGroup>
<SourceAFiles Include="$(RootDir)$(SourceA)\**\*.*" />
<SourceBFiles Include="$(RootDir)$(SourceB)\**\*.*" />
<SourceCFiles Include="$(RootDir)$(SourceC)\**\*.*" />
<SourceAllFiles Include="@(SourceAFiles);@(SourceBFiles);@(SourceCFiles)" />
</ItemGroup>
<CreateItem Include="@(SourceAFiles->Replace($(SourceA), $(RenameA)))">
<Output TaskParameter="Include" ItemName="RenamedSourceA" />
</CreateItem>
<CreateItem Include="@(SourceBFiles->Replace($(SourceB), $(RenameB)))">
<Output TaskParameter="Include" ItemName="RenamedSourceB" />
</CreateItem>
<CreateItem Include="@(SourceCFiles->Replace($(SourceC), $(RenameC)))">
<Output TaskParameter="Include" ItemName="RenamedSourceC" />
</CreateItem>
<ItemGroup>
<RenamedAllFiles Include="@(RenamedSourceA);@(RenamedSourceB);@(RenamedSourceC)" />
</ItemGroup>
<Message Text="%(SourceAllFiles.Identity)" Importance="high" />
<Message Text="%(RenamedAllFiles.Identity)" Importance="high" />
<Copy SourceFiles="@(SourceAllFiles)" DestinationFiles="@(RenamedAllFiles)" />
</Target>
</Project>
我有以下目录(例如)
./dirA/file1
./dirA/dir/file2
./dirB/file3
./dirB/dir/file4
./dirC/file5
我想将它们复制到不同的地方,例如:
./dirA_renamed/file1
./dirA_renamed/dir/file2
./dirB_renamed_differently/file3
./dirB_renamed_differently/dir/file4
./dirC_renam/file5
目录列表及其新名称不会经常更改,但我只想使用一个 Copy
。
我试过以下方法:
<ItemGroup>
<ToCopy Include=".\dirA">
<OutputDirName>dirA_renamed</OutputDirName>
</ToCopy>
<ToCopy Include=".\dirB">
<OutputDirName>dirB_renamed_differently</OutputDirName>
</ToCopy>
<ToCopy Include=".\dirC">
<OutputDirName>dirC_renam</OutputDirName>
</ToCopy>
</ItemGroup>
......
<CreateItem Include="%(ToCopy.Directory)\**\*.*">
<Output TaskParameter="Include" ItemName="FilesToCopy" />
</CreateItem>
<Copy SourceFiles="@(FilesToCopy)" DestinationFolder="@(FilesToCopy->'%(OutputDirName)')" />
但是没有任何反应。如果我输出FilesToCopy
,它是空的。我做错了什么?
硬编码方式是我知道的方式,但我知道你可以使用参数,我只是还没有完全弄明白,给你一个工作示例。
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
ToolsVersion="4.0" DefaultTargets="Build">
<PropertyGroup>
<RootDir>C:\DevDir</RootDir>
<SourceA>dirA</SourceA>
<SourceB>dirB</SourceB>
<SourceC>dirC</SourceC>
<RenameA>dirA_renamed</RenameA>
<RenameB>dirB_renamed_differently</RenameB>
<RenameC>dirC_renam</RenameC>
</PropertyGroup>
<Target Name="CopyDirTest" >
<ItemGroup>
<SourceDirA Include="$(RootDir)$(SourceA)\"/>
<SourceDirB Include="$(RootDir)$(SourceB)\" />
<SourceDirC Include="$(RootDir)$(SourceC)\" />
</ItemGroup>
<ItemGroup>
<SourceAFiles Include="$(RootDir)$(SourceA)\**\*.*" />
<SourceBFiles Include="$(RootDir)$(SourceB)\**\*.*" />
<SourceCFiles Include="$(RootDir)$(SourceC)\**\*.*" />
<SourceAllFiles Include="@(SourceAFiles);@(SourceBFiles);@(SourceCFiles)" />
</ItemGroup>
<CreateItem Include="@(SourceAFiles->Replace($(SourceA), $(RenameA)))">
<Output TaskParameter="Include" ItemName="RenamedSourceA" />
</CreateItem>
<CreateItem Include="@(SourceBFiles->Replace($(SourceB), $(RenameB)))">
<Output TaskParameter="Include" ItemName="RenamedSourceB" />
</CreateItem>
<CreateItem Include="@(SourceCFiles->Replace($(SourceC), $(RenameC)))">
<Output TaskParameter="Include" ItemName="RenamedSourceC" />
</CreateItem>
<ItemGroup>
<RenamedAllFiles Include="@(RenamedSourceA);@(RenamedSourceB);@(RenamedSourceC)" />
</ItemGroup>
<Message Text="%(SourceAllFiles.Identity)" Importance="high" />
<Message Text="%(RenamedAllFiles.Identity)" Importance="high" />
<Copy SourceFiles="@(SourceAllFiles)" DestinationFiles="@(RenamedAllFiles)" />
</Target>
</Project>