MSBuild复制特定文件和文件夹

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.

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>

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