Last post on MSBuild for today, promised.

MSBuild supports something called Item. This is basically the same as a data-type with an id attribute in Ant. Its main use in MSBuild is to specify inputs and outputs of tasks and targets - in Ant the references are only used for task inputs.

While I don't like the inputs/outputs for Target too much, I think the idea to have a task accept a reference as input and provide its output as a reference is useful. For some tasks it may be difficult to calculate the output, if possible at all, but as a general concept this may work.

The input for tasks like <copy> could be some type of file-collection, as would be the output. Let's assume we want to copy some files and add those that we've just copied to an archive.

What we'd do with Ant now

  <fileset id="templates" dir="styles">
    <patternset id="template-patterns">
      <include name="**/*.xsl"/>
    </patternset>
  </fileset>
  <copy todir="${build}">
    <fileset refid="templates"/>
  </copy>
  <zip destfile="files.zip">
    <fileset dir="${build}">
      <patternset refid="template-patterns"/>
    </fileset>
  </zip>

Let's assume all task can specify inputs (<copy> and <zip> would accept <fileset> among other things as inputs) and outputs via inputItems and outputItems attributes respectively. inputItems points to an existing project reference, outputItems creates such a reference.

Then we could write:

  <fileset id="templates" dir="styles">
    <include name="**/*.xsl"/>
  </fileset>
  <copy todir="${build}" inputItems="templates" 
        outputItems="copy-of-templates"/>
  <zip destfile="files.zip" inputItems="copy-of-templates"/>

We could even create a special TaskContainer that magically connected the output of task n to the input of task n+1, avoiding temporary references like "copy-of-templates":

  <fileset id="templates" dir="styles">
    <include name="**/*.xsl"/>
  </fileset>
  <pipe>
    <copy todir="${build}" inputItems="templates"/>
    <zip destfile="files.zip"/>
  </pipe>

Something that needs more thought, of course.

path: /en/dotNet/msbuild | #