title: MsBuild: Passing an ItemGroup with CallTarget
body: <p>I'm having some problems witht the scoping of item groups I create in an MSBuild script. Basically, what I want to do is to have two different targets - let's call them <code>RunUnitTests</code> and <code>RunIntegrationTests</code> - that generate an item group called <code>TestAssemblies</code> and then call <code>RunTests</code>, which uses <code>TestAssemblies</code> to determine which assemblies to run tests from. </p>
  
  <p>The two different targets for unit and integration tests both depend on the build target and get an item group with all compiled assemblies from there, but since the <code>RunTests</code> target will be called from different places, it can't really depend on either of them. Thus, I need to pass the item group to the common testrunner target somehow. However, this seems to be impossible, because changes to an item group within a target seems to be scoped to only work within that target.</p>
  
  <p>I've seen <a href="https://stackoverflow.com/questions/1088950/itemgroup-item-scope-alternatively-why-does-msbuild-hate-me">these</a> <a href="https://stackoverflow.com/questions/3265632/why-doesnt-msbuild-itemgroup-conditional-work-in-a-global-scope">posts</a>, but they only seem to confirm my fears, and suggest <code>DependsOnTarget</code> as a workaround - which won't work for me, since I need to get the items from different places on different runs.</p>
  
  <p>This is what I have so far:</p>
  
  <pre><code>&lt;Target Name="RunAllTests" DependsOnTarget="BuildProject"&gt;
      &lt;!-- In here, items created in BuildProject are available. --&gt;
      &lt;CallTarget Targets="RunUnitTests;RunIntegrationTests"&gt;
  &lt;/Target&gt;
  
  &lt;Target Name="RunUnitTests" DependsOnTarget="BuildProject"&gt;
      &lt;!-- In here, items created in BuildProject are available. --&gt;
      &lt;!-- One of those is @(UnitTestAssemblies) --&gt;
  
      &lt;CreateItem Include="@(UnitTestAssemblies)"&gt;
          &lt;Output TaskParameter="Include" ItemName="TestAssemblies" /&gt;
      &lt;/CreateItem&gt;
  
      &lt;CallTarget Targets="RunTests" /&gt;
  &lt;/Target&gt;
  
  &lt;!-- Then there's a similar target named RunIntegrationTests, which does the
       same as RunUnitTests except it includes @(IntegrationTestAssemblies) --&gt;
  
  &lt;Target Name="RunTests"&gt;
      &lt;!-- Here, I'd like to access @(TestAssemblies) and pass them to the NUnit
           task, but they have fallen out of scope. --&gt;
  &lt;/Target&gt;
  </code></pre>
  
  <p>Is there any way around this, or will I have to completely restructure my build script?</p>