Recursive Copy in MsBuild

01 September 2013

codemsbuild

Simply because I always forget the syntax for this, here’s how to recursively copy a set of files from one folder to another using the <Copy> task.

<Target Name="CopyNewTags">
	<ItemGroup>
		<FilesToCopy Include="$(FromThisFolder)**\*.*" />
	</ItemGroup>
	
	<Copy SourceFiles="@(FilesToCopy)"
		DestinationFolder="$(ToThisFolder)%(RecursiveDir)" />
</Target>

The magic, of course, is in using the multi-star notation in the ItemGroup include and in using the meta value %(RecursiveDir) in the destination folder attribute.

If you liked this post you can tweet it or follow me on Twitter!