Remove Files and Folders Copied From AfterBuild Target
<p>I would like to avoid hard coding the dll and folder names in the AfterClean target, is there a dynamic way to do this?  Ideally it would only delete the files and folders created by the Copy in the AfterBuild target.</p>

<p>I tried to simplify this by changing the DestinationFolder to include a subdirectory in the OutputPath.  The AfterClean target would only have to remove that subdirectory at this point.  However, some of the library's DLLImport paths don't take that subdirectory into consideration which results in a crash.</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; 
&lt;Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"&gt; 
  &lt;Target Name="AfterBuild"&gt; 
    &lt;ItemGroup&gt; 
      &lt;NativeLibs Include="$(MSBuildThisFileDirectory)..\lib\native\**\*.*" /&gt;
    &lt;/ItemGroup&gt; 
    &lt;Copy SourceFiles="@(NativeLibs)" DestinationFolder="$(OutputPath)\%(RecursiveDir)" /&gt; 
  &lt;/Target&gt; 
  &lt;Target Name="AfterClean"&gt;
    &lt;Delete Files="$(OutputPath)\LumiAPI.dll" /&gt; 
    &lt;Delete Files="$(OutputPath)\LumiCore.dll" /&gt; 
    &lt;Delete Files="$(OutputPath)\LumiInOpAPI.dll" /&gt; 
    &lt;RemoveDir Directories="$(OutputPath)\SPM" /&gt;
    &lt;RemoveDir Directories="$(OutputPath)\plugin" /&gt;
  &lt;/Target&gt; 
&lt;/Project&gt;
</code></pre>

<p>Project Structure:</p>

<p>src</p>

<ul>
<li><p>ConsumingProject</p>

<ul>
<li>ConsumingProject.csproj</li>
</ul></li>
<li><p>ConsumingProject.sln</p></li>
<li><p>packages</p>

<ul>
<li><p>my-project.5.7.0.12</p>

<ul>
<li><p>build</p></li>
<li><p>lib</p>

<ul>
<li><p>native</p>

<ul>
<li><p>plugin</p>

<ul>
<li>VenusDvc.dll</li>
</ul></li>
<li><p>SPM</p>

<ul>
<li>sSPM_1.bin</li>
</ul></li>
<li><p>LumiAPI.dll</p></li>
<li><p>LumiCore.dll</p></li>
<li><p>LumiInOpAPI.dll</p></li>
</ul></li>
<li><p>net45</p></li>
</ul></li>
<li><p>my-project.5.7.0.12.nupkg</p></li>
</ul></li>
</ul></li>
</ul>

<p>Essentially I want to delete all the files and folders that were copied from the native folder to the output of the project (ie LumiAPI.dll, LumiCore.dll, SPM (folder), eSPM_1.bin, etc).  However I want it to be generic enough so that if I add another folder to the native directory, it will delete those folders/files as well.</p>