编程的MSBuild递归复制使用通配符 [英] Programmatic MSBuild Recursive Copy with wildcards
问题描述
我创建一个MSBuild V4的任务,恰好需要调用拷贝任务递归复制一些文件(不压扁在目标目录结构)。
I am creating an MSBuild v4 task that happens to need to call the Copy task to recursively copy some files (without flattening the directory structure at the destination).
我想出了:
var copy = new Microsoft.Build.Tasks.Copy
{
BuildEngine = this.BuildEngine,
SourceFiles = new ITaskItem[] { new TaskItem(@"C:\source\**\*.foo") },
DestinationFolder = new TaskItem(@"c:\dest\\")
};
copy.Execute();
但我得到一个错误无法复制C:\source\ ** \ *包含.foo到c:\dest\ * - 路径中具有非法字符
but am getting an error 'Could not copy C:\source\**\*.foo to c:\dest\* - Illegal characters in path'
似乎没有成为务实调用多联机帮助,并已制定一个空白。任何想法?
There doesn't seem to be much online help for pragmatic invocation, and have drawn a blank. Any ideas?
感谢
乔恩
推荐答案
它看起来像复制任务没有递归的内在理解;下面的代码会导致复制任务,一旦每个文件级别上调用,这是由MSBuild的亚军处理。
It looks like the Copy task doesn't have an intrinsic understanding of recursion; the following code would cause the Copy task to be invoked once per file level, and this is handled by the MSBuild runner.
<ItemGroup>
<x Include="c:\source\**\*.foo" />
</ItemGroup>
<Copy SourceFiles="@(x)" DestinationFolder="c:\dest\%(RecursiveDir)" />
然而,由于复制任务似乎对待来源档案和DestinationFiles作为关联数组(每种类型ITaskItem的[]),我们只是进行了递归下降并手动建立这两个数组,execing之前
However, since the Copy task seems to treat SourceFiles and DestinationFiles as an associative array (each of type ITaskItem[]), we just performed a recursive descent and built up these two arrays manually, before execing it
这篇关于编程的MSBuild递归复制使用通配符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!