Recursive Copy in MsBuild

01 September 2013


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">
		<FilesToCopy Include="$(FromThisFolder)**\*.*" />
	<Copy SourceFiles="@(FilesToCopy)"
		DestinationFolder="$(ToThisFolder)%(RecursiveDir)" />

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!