Timo Willemsen
Timo Willemsen

Reputation: 8857

MSBuild copy specific files and folders

Lets say I have the following folder structure

app
-->folder1
----->subfolder2
----->subfolder3
-->folder2
----->subfolder4
-->folder3

And I want to use the Copytask to copy folder2 (including subfolders) and subfolder3 to my output.

How can I achieve that? Btw, I'm using MSBuild for a PHP website, and in the real situation there are a lot more subfolders and specific folders I want to copy.

Upvotes: 2

Views: 1300

Answers (2)

Jupaol
Jupaol

Reputation: 21365

You could try RoboCopy:

<UsingTask AssemblyFile="MSBuild.ExtensionPack.dll" TaskName="MSBuild.ExtensionPack.FileSystem.RoboCopy"/>

<MSBuild.ExtensionPack.FileSystem.RoboCopy 
  Source="$(YourSourcePath)" 
  Destination="$(YourOutputPath)" 
  Files="*.*"
  Options="/MIR"/>

The /MIR option duplicates the whole folder tree including empty folders

Robocopy reference:

MSBuild extensions pack

Upvotes: 1

Richard Banks
Richard Banks

Reputation: 12546

Create an item group with folder2 and subfolder3 in it and then use the copy task.

For example:

<ItemGroup>
  <sourceFiles Include="app\folder1\subfolder3\**\*.*" />
  <sourceFiles Include="app\folder2\**\*.* />
</ItemGroup>

<Copy SourceFiles="@(sourceFiles)" DestinationFolder="c:\output\%(RecursiveDir)"></Copy>

Upvotes: 3

Related Questions