I wonder how to synchronize two folders, including subfolders, using MSBuild.
I like to do
a) to copy all files from the source folder to the dest folder that are newer or do not exist in the dest folder
and
b) delete all files from the dest folder that do not exist (anymore) in the source folder
a) pretty easy using the <Copy>
task, but how can I do b)?
This is my build file so far:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0" DefaultTargets="Backup"> <PropertyGroup> <SourceFolder>C:\source</SourceFolder> <DestFolder>C:\dest</DestFolder> </PropertyGroup> <ItemGroup> <FilesToCopy Include="$(SourceFolder)\**" /> </ItemGroup> <Target Name="Backup"> <Copy SourceFiles="@(FilesToCopy)" DestinationFiles="@(FilesToCopy->'$(DestFolder)\%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="True" /> </Target> </Project>
source share