Sabuncu
Sabuncu

Reputation: 5274

How to have MSBuild act on a list of folders

Using the following MSBuild task, I am able to get all the folders below the current directory:

First, define the related environment variable:

set MSBUILDENABLEALLPROPERTYFUNCTIONS=1

MSBuild file:

  <Target Name="Christian_T">
    <ItemGroup>
      <Folders Include="$([System.IO.Directory]::GetDirectories('.', '*',
        System.IO.SearchOption.AllDirectories))"/>
    </ItemGroup>
    <Message Text="%(Folders.Identity)" />
  </Target>

How can I run MSBuild in each of the folders collected within Folders.Identity?

If you think my approach above is altogether wrong, then please feel free to set me straight. My ultimate goal is to be able to invoke msbuild at the top folder, and have it build all csproj files in the subfolders underneath.

Upvotes: 0

Views: 699

Answers (1)

mageos
mageos

Reputation: 1291

The trick is to use MSBuild batching that will expand an ItemGroup with multiple items in it.

%(Folders.Identity)

You can use that syntax just about anywhere that takes a single value and MSBuild will automatically call that task for each item in the ItemGroup. For more information see the documentation:

https://learn.microsoft.com/en-us/visualstudio/msbuild/msbuild-batching?view=vs-2017

Upvotes: 2

Related Questions