Question

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?

Was it helpful?

Solution 2

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

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

OTHER TIPS

If you want to preserve directory structure use this:

<Copy SourceFiles="@(None)" DestinationFolder="$(NewDirectory)\%(None.RelativeDir)" />
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top