dotnet / msbuild

The Microsoft Build Engine (MSBuild) is the build platform for .NET and Visual Studio.
https://docs.microsoft.com/visualstudio/msbuild/msbuild
MIT License
5.22k stars 1.35k forks source link

Add a parameter to the MSBuild Copy task for recursive copying #334

Open cdmihai opened 8 years ago

cdmihai commented 8 years ago

Currently one has to use this idiom (http://blogs.msdn.com/b/msbuild/archive/2005/11/07/490068.aspx) to recursively copy. Without resorting to invoking robocopy or other platform specific commands.

The Copy task should have a RecursiveCopy parameter to enable this behaviour.

rainersigwald commented 8 years ago

A difficulty here is that Copy currently only accepts a list of files (well, ITaskItem, but it's assumed they're all files) as its input. A recursive option would require directory inputs.

Additionally, this would make it even more difficult to construct incrementality around a Copy task. As is, you can define a list of items and a list of destinations outside a <Target>, then use them as Inputs and Outputs for that target. That wouldn't work with a recursive copy, because we wouldn't be able to know what the outputs should be outside of the Copy task itself.

cdmihai commented 8 years ago

Incrementality might be cheaply provided by the SkipUnchangedFiles flag in this line: https://github.com/Microsoft/msbuild/blob/xplat/src/XMakeTasks/Copy.cs#L551

In case of a recursive copy the code that calls DoCopyIfNecessary would need to first compute the recursive sourceFile / destinationFile pairs and then let DoCopyIfNecessary copy them if necessary.

All this behaviour could be triggered by a RecursiveCopy task parameter. If the flag is false / not present, then the old Copy task behaviour would execute. This should take care of backwards compatibility.