title: Determining outputs of a ProjectReference in MSBuild without triggering redundant rebuilds
body: <p>As part of a solution containing many projects, I have a project that references (via a <code>&lt;ProjectReference&gt;</code> three other projects in the solution, plus some others). In the <code>AfterBuild</code>, I need to copy the outputs of 3 specific dependent projects to another location.</p>
  
  <p>Via various SO answers, etc. the way I settled on to accomplish that was:</p>
  
  <pre><code>    &lt;MSBuild 
          Projects="@(ProjectReference)" 
          Targets="Build" 
          BuildInParallel="true" 
          Condition="'%(Name)'=='ProjectA' OR '%(Name)'=='ProjectB' OR '%(Name)'=='ProjectC'"&gt;
          &lt;Output TaskParameter="TargetOutputs" ItemName="DependentAssemblies" /&gt;
      &lt;/MSBuild&gt;
      &lt;Copy SourceFiles="@(DependentAssemblies)" DestinationFolder="XX" SkipUnchangedFiles="true" /&gt;
  </code></pre>
  
  <p>However, I ran into problems with this. The <code>&lt;MSBuild</code> step's <code>IncrementalClean</code> task ends up deleting a number of the outputs of <code>ProjectC</code>. When running this under VS2008, a <code>build.force</code> file being deposited in the <code>obj/Debug</code> folder of ProjectC which then triggers ProjectC getting rebuilt if I do a Build on the entire solution if the project containing this <code>AfterBuild</code> target, whereas if one excludes this project from the build, it [correctly] doesn't trigger a rebuild of ProjectC (and <em>critically</em> a rebuild of all dependents of ProjectC). This may be VS-specific trickery in this case which would not occur in the context of a TeamBuild or other commandline MSBuild invocation (but the most common usage will be via VS so I need to resolve this either way)</p>
  
  <p>The dependent projects (and the rest of the solution in general) have all been created interactively with VS, and hence the <code>ProjectRefence</code>s contain relative paths etc. I've seen mention of this being likely to causing issues - but without a full explanation of why, or when it'll be fixed or how to work around it. In other words, I'm not really interested in e.g. converting the <code>ProjectReference</code> paths to absolute paths by hand-editing the .csproj.</p>
  
  <p>While it's entirely possible I'm doing something stupid and someone will immediately point out what it is (which would be great), be assured I've spent lots of time poring over <code>/v:diag</code> outputs etc. (although I havent tried to build a repro from the ground up - this is in the context of a relatively complex overall build)</p>