This is a little trick to copy files from a regular expression with MSBuild.
With this example it becomes possible to use wildcards to identity to elements to copy.
<Target Name="BeforeBuild">
[...]
<ItemGroup>
<\_FoldersToCopy Include="$(ProjectDir)MyFolder\*TargetFolderSuffix\*.ext" />
</ItemGroup>
<Copy SourceFiles="@(_FoldersToCopy)"
DestinationFolder="@(_FoldersToCopy->'$(TargetDir)MyFolder\%(RecursiveDir)')" />
[...]
</Target>
This is very useful when you application uses a plugin pattern and you wish to copy all the libraries to the output directory.
Remarques
- If you put the itemGroup outside of the BeforeBuild target, Visual Studio will erase it when csproj is saved.
- Sources : (https://msdn.microsoft.com/fr-fr/library/3e54c37h.aspx)[ Copy Task sur MSDN]