Reputation: 919
I'm unable to copy subfolders and files with this code:
<ItemGroup>
<Compile Include="C:\Test\Folder1\text.txt"/>
<Compile Include="C:\Test\text1.txt"/>
</ItemGroup>
<Copy SourceFiles="@(Compile)" DestinationFiles="@(Compile->'C:\Destination\%(RecursiveDir)%(Filename)%(Extension)')" />
I get this error: Could not find a part of the path.
How to copy C:\Test\ files and subfolders to C:\Destination\ with msbuild ?
Thanks in advance for your help.
Upvotes: 1
Views: 3424
Reputation: 496
The same as in response above, but without additional list transformation:
<ItemGroup>
<Compile Include="C:\Test\**\Folder1\text.txt"/>
<Compile Include="C:\Test\**\text1.txt"/>
</ItemGroup>
<Copy SourceFiles="@(Compile)" DestinationFolder="C:\Destination\%(RecursiveDir)" />
Upvotes: 3
Reputation: 1282
In order for the RecursiveDir metadata to be populated, you must specify a recursive wildcard (double asterisks) in your items' paths. The **
wildcard will mark the relative point at which the RecursiveDir should be applied. In your example, it sounds like you'd want to add the **
wildcard after C:\Test
, so your code would need to look like the following example:
<ItemGroup>
<Compile Include="C:\Test\**\Folder1\text.txt"/>
<Compile Include="C:\Test\**\text1.txt"/>
</ItemGroup>
<Copy SourceFiles="@(Compile)" DestinationFiles="@(Compile->'C:\Destination\%(RecursiveDir)%(Filename)%(Extension)')" />
Adding the wildcard as shown above will copy the files to the following locations:
C:\Destination\text1.txt
C:\Destination\Folder1\text.txt
Upvotes: 3