How do I move a bunch of files using a Move MSBuil

2020-04-02 17:33发布

问题:

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.

So I composed this:

<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.

The files are definitely there.

What am I doing wrong? How do I have the files moved?

回答1:

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 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>


标签: msbuild