title: How can I use perform MSBuild batching on Items that don't represent files?
body: <p>The MSBuild documentation hints in several places that Items aren't necessarily the same as files.</p>
  <blockquote>
  <p><a href="http://msdn.microsoft.com/en-us/library/ms171453.aspx" rel="nofollow noreferrer">&quot;MSBuild items are inputs into the build system, and they typically represent files.&quot;</a></p>
  <p><a href="http://msdn.microsoft.com/en-us/library/dd997067.aspx" rel="nofollow noreferrer">&quot;Items are objects that typically represent files.&quot;</a></p>
  </blockquote>
  <p>However, I can't seem to find any examples where Items do not represent files. In particular, I would like to perform batching over a set of non-file items. But every item that I create, even from a custom build task, somehow acquires file-like metadata (FullPath, RootDir, Filename, Extension, etc.). Furthermore, I'm confused about the ramifications of setting the Inputs of a target to a set of items that aren't files, and what to use as that target's Outputs.</p>
  <p>Does anybody have an example of using non-file Items to perform batching in MSBuild?</p>
  <p><strong>edit</strong></p>
  <p>Sorry for taking so long to come up with an example. I understand things a bit more, but I'm still uncertain (and there seems to be a complete lack of documentation about this). Everything here is going off my recollection; I'm not at my work computer right now, so I can't verify any of it.</p>
  <p>In my experience, MSBuild doesn't like to build multiple configurations of a .sln file in one go. So, this:</p>
  <pre><code>msbuild.exe SampleMSBuild.sln /p:Configuration=Debug%3BRelease
  </code></pre>
  <p>(The encoded semicolon being necessary so that it doesn't try to define multiple properties.)</p>
  <p>Produces this:</p>
  <pre><code>&quot;D:\src\SampleMSBuild\SampleMSBuild.sln&quot; (default target) (1) -&gt;
  (ValidateSolutionConfiguration target) -&gt;
    D:\src\SampleMSBuild\SampleMSBuild.sln.metaproj : error MSB4126: The 
    specified solution configuration &quot;Debug;Release|Any CPU&quot; is invalid. 
    Please specify a valid solution configuration using the Configuration 
    and Platform properties (e.g. MSBuild.exe Solution.sln 
    /p:Configuration=Debug /p:Platform=&quot;Any CPU&quot;) or leave those properties 
    blank to use the default solution configuration. 
    [D:\src\SampleMSBuild\SampleMSBuild.sln]
  </code></pre>
  <p>So, it seems like it should be possible to use batching and items to handle this.</p>
  <pre><code>&lt;Project xmlns=&quot;http://schemas.microsoft.com/developer/msbuild/2003&quot; 
           DefaultTarget=&quot;Rebuild&quot; 
           ToolsVersion=&quot;4.0&quot;&gt;
    &lt;ItemGroup&gt;
      &lt;Configurations Include=&quot;Debug&quot; /&gt;--&gt;
      &lt;Configurations Include=&quot;Release&quot; /&gt;--&gt;
    &lt;/ItemGroup&gt;
  
    &lt;UsingTask TaskName=&quot;LogMetadata&quot;
               TaskFactory=&quot;CodeTaskFactory&quot;
               AssemblyFile=&quot;$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll&quot;&gt;
      &lt;ParameterGroup&gt;
        &lt;Items ParameterType=&quot;Microsoft.Build.Framework.ITaskItem[]&quot; 
               Required=&quot;true&quot; /&gt;
      &lt;/ParameterGroup&gt;
      &lt;Task&gt;
        &lt;Code Type=&quot;Fragment&quot; Language=&quot;cs&quot;&gt;
          &lt;![CDATA[
          foreach (var item in Items) {
            Console.Write(item.ItemSpec);
            Console.Write(&quot; {&quot;);
            foreach (string metadataKey in item.MetadataNames) {
              Console.Write(metadataKey);
              Console.Write(&quot;=\&quot;&quot;);
              Console.Write(item.GetMetadata(metadataKey).
                  ToString().Replace(&quot;\&quot;&quot;, &quot;\\\&quot;&quot;));
              Console.Write(&quot;\&quot; &quot;);
            }
            Console.WriteLine(&quot;}&quot;);
          }]]&gt;
        &lt;/Code&gt;
      &lt;/Task&gt;
    &lt;/UsingTask&gt;
  
    &lt;Target Name=&quot;Rebuild&quot;&gt;
      &lt;LogMetadata Items=&quot;%(Configurations.Identity)&quot; /&gt;
    &lt;/Target&gt;
  &lt;/Project&gt;
  </code></pre>
  <p>Which produces this:</p>
  <pre><code>Debug {
    FullPath=&quot;D:\src\SampleMSBuild\Debug&quot; 
    RootDir=&quot;D:\&quot; 
    Filename=&quot;Debug&quot; 
    Extension=&quot;&quot; 
    RelativeDir=&quot;&quot; 
    Directory=&quot;src\SampleMSBuild\&quot; 
    RecursiveDir=&quot;&quot; 
    Identity=&quot;Debug&quot; 
    ModifiedTime=&quot;&quot; 
    CreatedTime=&quot;&quot; 
    AccessedTime=&quot;&quot; 
  }
  Release {
    FullPath=&quot;D:\src\SampleMSBuild\Release&quot; 
    RootDir=&quot;D:\&quot; 
    Filename=&quot;Release&quot; 
    Extension=&quot;&quot; 
    RelativeDir=&quot;&quot; 
    Directory=&quot;src\SampleMSBuild\&quot; 
    RecursiveDir=&quot;&quot; 
    Identity=&quot;Release&quot; 
    ModifiedTime=&quot;&quot; 
    CreatedTime=&quot;&quot; 
    AccessedTime=&quot;&quot;
  }
  </code></pre>
  <p>As you can see, the items have all kinds of file metadata attached to them. I can't drop the Include attribute, since it's required, but I could synthesize the items in a custom task. HOWEVER, when I do that, they still somehow magically gain all the same file metadata.</p>
  <p>What are the ramifications of this? Since I haven't specified these as Inputs or Outputs to a target, will the file metadata cause any problems? Will the build system skip over targets, or build more than it needs to, because the files specified in the Items' FullPath metadata do not exist? What if those files did exist? Would it cause any problems?</p>