title: Copy Files in Visual Studio Post Build Event
body: <p>I want to copy all files recursivly with given file extensions after the build process succeeds.</p>
  
  <p>Robocopy</p>
  
  <pre><code>ROBOCOPY %source% %destination% /S *.as?x *.xls? *.mrt
  </code></pre>
  
  <p>xcopy</p>
  
  <pre><code>xcopy .\*.as?x %destination% /SY
  xcopy .\*.xls? %destination% /SY
  xcopy .\*.mrt %destination% /SY
  </code></pre>
  
  <p>I have tried to insert both possibilities in the post build section in visual studio. RoboCopy exits with error: Error  1   The command "ROBOCOPY source destination /S *.as?x *.xls? *.mrt" exited with code 1.
  Some files where copied but to the wrong folder (_PublishedWebsites).</p>
  
  <p>xcopy also copy to the wrong directory (_PublishedWebsites) and also does not copy all files.</p>
  
  <p>In the command line both commands work as expected.</p>
  
  <h2>Update</h2>
  
  <p>I have updated my robocopy command:</p>
  
  <pre><code>ROBOCOPY $(MSBuildProjectDirectory) $(MSBuildProjectDirectory)\..\..\..\EDP\Web\Modules\Invoice\Web /S *.as?x *.xls? *.mrt
  </code></pre>
  
  <p>Now the files are copied to the correct location, but the return code of robocopy causes an visual studio error.</p>
  
  <p>Here a solution with help of <a href="https://stackoverflow.com/questions/5470828/using-robocopy-with-visual-studio-2010-post-build-and-pre-build-events">this</a>:</p>
  
  <pre><code>call ROBOCOPY $(MSBuildProjectDirectory) $(MSBuildProjectDirectory)\..\..\..\EDP\Web\Modules\Invoice\Web /S *.as?x *.xls? *.mrt
  if %errorlevel% leq 1 exit 0 else exit %errorlevel%
  </code></pre>
  
  <h2>Preferred solution</h2>
  
  <pre><code>&lt;ItemGroup&gt;
      &lt;SourceFiles Include="$(MSBuildProjectDirectory)\**\*.js"/&gt;
      &lt;SourceFiles Include="$(MSBuildProjectDirectory)\**\*.html"/&gt;
      &lt;SourceFiles Include="$(MSBuildProjectDirectory)\**\*.css*"/&gt;
      &lt;SourceFiles Include="$(MSBuildProjectDirectory)\**\*.png"/&gt;
      &lt;SourceFiles Include="$(MSBuildProjectDirectory)\**\*.as?x"/&gt;
  &lt;/ItemGroup&gt;
  
  &lt;Target Name="AfterBuild"&gt;
      &lt;Copy
         SourceFiles="@(SourceFiles)"
         DestinationFiles="@(SourceFiles-&gt;'%(MSBuildProjectDirectory)..\..\..\EDP\Web\Modules\DMS\Web\%(RecursiveDir)%(Filename)%(Extension)')"
      /&gt;
  &lt;/Target&gt;
  </code></pre>