2
<Target Name="Build">
...

    <MSBuild
            Projects="$(MSBuildProjectFile)"
            Condition="'@(FilesToCompile)' != ''"
            Targets="buildcpp"
            Properties="CPPFILE=%(FilesToCompile.FullPath);OBJFILE=$(ObjectFolder)\%(FilesToCompile.Filename).doj;IncludeDirs=$(IncludeDirs)"
        />

FilesToCompile is an ItemGroup of all .cpp files.

When I look at the build log, it shows the target buildcpp being run for each of the files in CPPFILE.

I understand that is what I logically want to happen but my question is, what rule of element <MSBuild> or the MSBuild schema causes task MSBuild to be executed for each value of CPPFILE?

In short, where in the documentation does it state that is what will happen?

I want to pass in an entire ItemGroup once instead of calling the MSBuild target once for each item.

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Bob
  • 4,576
  • 7
  • 39
  • 107
  • @HansPassant so if I wanted to pass in an entire `ItemGroup` and only once, I would have to first assign it to a `Property` and then set that equal to the ` – Bob Oct 05 '17 at 16:38
  • @HansPassant I want to pass in an `ItemGroup` all at once instead of one Task call per item. – Bob Oct 05 '17 at 16:41
  • https://msdn.microsoft.com/en-us/library/ms171473.aspx?f=255&MSPPError=-2147217396 – stijn Oct 05 '17 at 18:07

1 Answers1

1

The msbuild concept this is based on is called "batching" - in your case task batching (see MSBuild's task batching documentation).

Any task that contains a %() reference to an item group will be split up into batches that share the same metadata and the task will be executed once for each batch. When using built-in metadata like Identity or FullPath, this essentially means "execute this task for ever item", though there can also be more complex use cases.

Martin Ullrich
  • 94,744
  • 25
  • 252
  • 217