如何使用Move MSBuild任务和通配符移动一堆文件? [英] How do I move a bunch of files using a Move MSBuild task and a wildcard?
问题描述
我有一个文件夹,该文件的名称以App_Web_
开头并以.dll
结尾.我不知道这些部分之间的内容,也不知道文件的数量.我需要MSBuild才能将这些文件移动到另一个文件夹中.
I have a folder with files that have names starting with App_Web_
and ending with .dll
. I don't know what's in between those parts and I don't know the number of files. I need MSBuild to move those files into another folder.
所以我写了这个:
<Move
SourceFiles="c:\source\App_Web_*.dll"
DestinationFolder="c:\target"
/>
但是当目标运行时,我得到以下输出:
but when the target runs I get the following output:
error MSB3680: The source file "c:\source\App_Web_*.dll" does not exist.
文件肯定在那里.
我做错了什么?如何移动文件?
What am I doing wrong? How do I have the files moved?
推荐答案
您不能直接在任务参数中使用正则表达式.您需要创建一个包含文件列表的项目以移动并将其内容传递给任务:
You cannot use regular expression directly in task parameters. You need to create an item containing list of files to move and pass its content to the task:
<ItemGroup>
<FilesToMove Include="c:\source\App_Web_*.dll"/>
</ItemGroup>
MSBuild将扩展正则表达式,然后再将其传递给任务执行器.因此,稍后在某些目标中,您可以调用Move
任务:
MSBuild will expand regular expression before passing it to the task executor. So later in some target you may invoke Move
task:
<Target Name="Build">
<Move
SourceFiles="@(FilesToMove)"
DestinationFolder="C:\target"
/>
</Target>
这篇关于如何使用Move MSBuild任务和通配符移动一堆文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!