views:

609

answers:

2

I have this bit of an msbuild project that is making me wonder why it the outcome is the way it is. Not that it is causing an issue or anything of the sort, but I would like to try and better my understanding of it.

<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="TestTarget1;TestTarget2" ToolsVersion="3.5">

  <ItemGroup>
    <PathDir Include="C:\RootDir\UniqueDir1"/>
    <PathDir Include="C:\RootDir\UniqueDir2" />
  </ItemGroup>

  <Target Name="TestTarget1" Outputs="%(PathDir.Identity)">
    <PropertyGroup>
      <RootPath>%(PathDir.Identity)</RootPath>
    </PropertyGroup>

    <ItemGroup>
      <SubDirectory Include="Common1"/>
      <SubDirectory Include="Common2"/>
    </ItemGroup>

    <CreateItem Include="@(SubDirectory->'$(RootPath)\%(Identity)')">
      <Output TaskParameter="Include" ItemName="FullPath"/>
    </CreateItem>

    <Message Text="@(FullPath)"/>
  </Target>

  <Target Name="TestTarget2">
    <Message Text="@(FullPath)"/>
  </Target>

</Project>

So I have two main paths that are unique, and within each I have two directories with the same names in each of the unique paths. In target1, I am batching against the identity of the items in PathDir, and then performing a transform on item SubDirectory, which contains the common folder names found in the unique directories, to create a new item containing the full paths. So anyways, after that, the output for the targets is as follows:

Target 1:

  C:\RootDir\UniqueDir1\Common1;C:\RootDir\UniqueDir1\Common2
  C:\RootDir\UniqueDir2\Common1;C:\RootDir\UniqueDir2\Common2

Target 2:

  C:\RootDir\UniqueDir1\Common1;C:\RootDir\UniqueDir1\Common2;C:\RootDir\UniqueDir2\Common1;C:\RootDir\UniqueDir2\Common2

So my question I guess is ... why does target1 only display the directories containing the directory it is batching against? I know it probably has to do with batching, but thats all I know.

A: 

is it not the

<PropertyGroup>
  <RootPath>%(PathDir.Identity)</RootPath>
</PropertyGroup>

Coupled with

<CreateItem Include="@(SubDirectory->'$(RootPath)\%(Identity)')">

that is causing the 2 x 2 as opposed to the 1x4

Preet Sangha
A: 

When a target is batched it exectues independently of other executions of the same batched target. So in the first execution you populated the FullPath item to the contents

C:\RootDir\UniqueDir1\Common1;C:\RootDir\UniqueDir1\Common2

Then on the second execution of the target you populated the value of FullPath to be

C:\RootDir\UniqueDir2\Common1;C:\RootDir\UniqueDir2\Common2

Since items are not visible to the same batched target the second pass doesn't "see" that FullPath item. But when the TestTarget1 is completed the values for FullPath are combined into a single value which is.

C:\RootDir\UniqueDir1\Common1;C:\RootDir\UniqueDir1\Common2;C:\RootDir\UniqueDir2\Common1;C:\RootDir\UniqueDir2\Common2

Does that clear it up? Batching can be kind of confusing at times.

Here are some links on batching:

Sayed Ibrahim Hashimi