In my cpp project file I have an item group defined as such:

<ItemGroup>
    <None Include="dir1\file1" />
    <None Include="dir1\blah.dll" />
    <None Include="dir1\dir2\something.dll" />
    <None Include="dir1\dir2\dir3\another_file.dll" />
</ItemGroup>

I have an AfterBuild target whereby I want to copy the above files (and preserve their directory structure) into a new location, e.g.:

<Target Name="AfterBuild">
    <Copy SourceFiles="@(None)" DestinationFiles="@(None->'$(NewDirectory)%(RecursiveDir)%(Filename)%(Extension)')" ContinueOnError="false" />
</Target>

NB: $(NewDirectory) is defined somewhere else.

However the above just copies the files to the $(NewDirectory) but ignores the directory structure of the item list (i.e. Dir1, Dir2 and Dir3). Is there a way to do this without having to create a new list?

有帮助吗?

解决方案 2

I just worked this out! Replace %(Recursive) with %(RelativeDir), i.e.:

<Copy SourceFiles="@(None)" DestinationFiles="@(None->'$(NewDirectory)%(RelativeDir)%(Filename)%(Extension)')" ContinueOnError="false" />

其他提示

If you want to preserve directory structure use this:

<Copy SourceFiles="@(None)" DestinationFolder="$(NewDirectory)\%(None.RelativeDir)" />
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top