title: What is incremental clean in msbuild and when is it triggered?
body: <p>I am debugging a bug in my build process that happens occasionally but I can't directly reproduce it.  I'm using msbuild with teamcity. </p>
  
  <p>I have a dependency hierarchy like this:</p>
  
  <pre><code>Some.Interop.dll
     Dependency-&gt; SharedDllABC.dll
  
  SomeService.exe
     Depenendcy-&gt; Some.Interop
  </code></pre>
  
  <p>Usually the final service exectuable gets in its release directory:</p>
  
  <pre><code>Some.Interop
  SharedDllABC.Dll
  ServiceExectuable.exe
  </code></pre>
  
  <p>However I can see in our msbuild logs that sometimes the tertiary dependency gets deleted during an Incremental Clean after everything is built resulting in:</p>
  
  <pre><code>Some.Interop
  ServiceExectuable.exe
  </code></pre>
  
  <p>You can see it here in the msbuild log:</p>
  
  <pre><code>[src\SomeService\SomeService.csproj] _TimeStampAfterCompile
  [12:32:43]:  [src\SomeService\SomeService.csproj] Compile
  
  // some other targets
  
  [12:32:43]:  [src\SomeService\SomeService.csproj] _CopyFilesMarkedCopyLocal
  [12:32:43]:      [_CopyFilesMarkedCopyLocal] Copy
  [12:32:43]:          [Copy] Copying file from "C:Projects\trunk\src\Some.Interop\bin\Release\Some.Interop.dll" to "bin\Release\Some.Interop.dll".
  
  // some other targets
  
  [src\Project\SomeService\SomeService.csproj] IncrementalClean
  [18:54:42]:         [IncrementalClean] Delete
  [18:54:42]:             [Delete] Deleting file "C:\Projects\trunk\src\Project\SomeService\bin\Release\SharedDllABC.dll".
  [18:54:42]:             [Delete] Deleting file "C:\Projects\trunk\src\Project\SomeServiceService\bin\Release\SharedDllABC.pdb".
  [18:54:42]:     [src\Project\SomeService\SomeService.csproj] CoreBuild
  [18:54:42]:     [src\Project\SomeService\SomeService.csproj] AfterBuild
  [18:54:42]:     [src\Project\SomeService\SomeService.csproj] Build
  </code></pre>
  
  <p>This is my direct msbuild output, I just changed the project names/dll names to match my example.  By the time this Incremental Clean has occurred the <code>SomeService.csproj</code> has already been built.  You can see that its not getting copied. However in other msbuild logs it does properly get copied and then the incremental clean doesn't delete it.  </p>
  
  <p>I think incrementeal clean from <a href="http://social.msdn.microsoft.com/Forums/en-US/tfsbuild/thread/2a2bcbb4-8afe-41da-a07d-822f50f2ea72" rel="noreferrer">this post</a> is supposed to clean dll's that were created from previous builds, but that doesn't explain how this dll didn't get built when most of the time it does. In visual studio this always works as well.</p>
  
  <p>I guess I just want to know what exactly is <code>Incremental clean</code>, what causes it to kick in, and maybe what things I should look for when debugging a situation like this (assembly versions, timestamps, etc?)</p>