In a project recently we needed a way to generate the combinations of two ItemGroups to build a release package with folders for environments and several copies of a program within each environment folder.

As MSBuild does not have an easy way to iterate through two collections to build such a combinations we need to take some advantage of how MSBuild handles collections.

We can take advantage of this by creating a new ItemGroup using one of the ItemGroups we want to combine and creating a new property on this new ItemGroup using the collection defined by the second ItemGroup we want to combine

The below snippet shows this in action. Try it out by copying into a text file, saving it, and running it with MSBuild.exe.