title: MSBuild Copying from IntermediateOutputPath After Build Completion
body: <p>I am using <a href="https://github.com/vc3/Afterthought" rel="nofollow">Afterthought</a> (similar to PostSharp) to apply post build changes to some code by modifying the output assembly. Currently, my project file has something like this within (abbreviated):</p>
  
  <pre><code>&lt;Target Name="AfterBuild"&gt;
    &lt;AfterThoughtTask TargetAssembly="$(TargetPath)" AmendWith="$(TargetDir)Amendments.dll" /&gt;
  &lt;/Target&gt;
  </code></pre>
  
  <p>Basically it's saying: after the build, use the AfterThoughtTask which runs a process to modify the output assembly with code found in Amendments.dll. This works just fine as I'd expect, and the MyProject.dll output to <code>MyProject\bin\Debug\MyProject.dll</code> is amended with the additional code. </p>
  
  <p>Then I make this slight change to my project file:</p>
  
  <pre><code>&lt;PropertyGroup&gt;
    &lt;OutputPath&gt;SomeOtherProjectLocation\bin\&lt;/OutputPath&gt;
  &lt;/PropertyGroup&gt;
  </code></pre>
  
  <p>So all I've done is change the output path. Now I debug <code>AfterThoughtTask</code>, and hit a breakpoint after all the code has been executed. When I'm stopped on this breakpoint, the file <code>SomeOtherProjectLocation\bin\MyProject.dll</code> (which is the file I intended to amend, sitting in the folder I expect it to be in) appears to be amended (has a file size of 117kb vs 103kb when unamended). It appears as if things are going fine at this point. Then I release the breakpoint, and suddenly the file size drops back to 103kb, somehow getting replaced with the original unamended file. Looking at the diagnostic build report, <code>AfterThoughtTask</code> is the very last task run with no reported file copies after it.</p>
  
  <p>Running again at the same breakpoint, I see that the file sitting in the <code>IntermediateOutputPath</code> directory (obj\Debug) is still 103kb (unamended), so I try to see if that is the file that is overwriting the amended one. When I'm at the breakpoint (the end of the task execution, but before control is given back to the build), I rename the file in the <code>IntermediateOutputPath</code> directory to MyProject.dll_hidden. I get no errors, but my file is no longer written over.</p>
  
  <p>So I can only assume that the file is being copied from the <code>IntermediateOutputPath</code> directory over the target file, but the build log doesn't seem to indicate this, and I don't understand why changing the <code>OutputPath</code> would make it happen this way vs. how it was acting before with the default <code>OutputPath</code>. Anyone have any guidance here? Thanks in advance.</p>