title: Synchronize two folders using MSBUILD
body: <p>I wonder how to synchronize two folders including subfolders using MSBuild.</p>
  
  <p>What I like to do is </p>
  
  <p>a) to copy all files from the source folder to the dest folder that are newer 
     or don't exist in the dest folder</p>
  
  <p>and</p>
  
  <p><strong>b) to remove all files from the dest folder that don't exist (anymore) in the 
     source folder</strong></p>
  
  <p>a) is pretty easy using the <code>&lt;Copy&gt;</code> task but how can I accomplish b) ?</p>
  
  <p>This is my build file so far:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" 
      ToolsVersion="4.0" 
      DefaultTargets="Backup"&gt;
      &lt;PropertyGroup&gt;
          &lt;SourceFolder&gt;C:\source&lt;/SourceFolder&gt;
          &lt;DestFolder&gt;C:\dest&lt;/DestFolder&gt;
      &lt;/PropertyGroup&gt;
      &lt;ItemGroup&gt;
          &lt;FilesToCopy Include="$(SourceFolder)\**" /&gt;
      &lt;/ItemGroup&gt;
      &lt;Target Name="Backup"&gt;
          &lt;!-- copy all files from the source folder to the dest folder 
              that are newer or don't exist in the dest folder --&gt;
          &lt;Copy 
              SourceFiles="@(FilesToCopy)" 
              DestinationFiles="@(FilesToCopy-&gt;'$(DestFolder)\%(RecursiveDir)%(Filename)%(Extension)')" 
              SkipUnchangedFiles="True" /&gt;
          &lt;!-- TODO: remove all files from the dest folder 
              that don't exist in the source folder --&gt;
      &lt;/Target&gt;
  &lt;/Project&gt;
  </code></pre>