I want to create an ItemGroup of all bin
directories within a given directory excluding all bin
directories within given sub directories, e.g.:
MyDirectory\
bin\
ext\
bin\
lib\
lib1\
bin
samples\
sample1\
bin\
src\
bin\
I want to delete all bin directories in MyDirectory, excluding all bin directories of ext and lib (i.e. delete samples\sample1\bin and src\bin).
This is what I came up with originally:
<ItemGroup>
<ExcludedDirs Include="$(MyDirectory)\ext" />
<ExcludedDirs Include="$(MyDirectory)\lib" />
<BinDirs Include="$(MyDirectory)\**\bin" />
<BinDirs Remove="$(MyDirectory)\%(ExcludedDirs.Identity)\**" />
</ItemGroup>
That doesn't work due to MSBuild - ItemGroup of all bin directories within subdirectories which is why I came up with the following:
<ItemGroup>
<ExcludedDirs Include="$(MyDirectory)\ext" />
<ExcludedDirs Include="$(MyDirectory)\lib" />
<BinDirs Include="$([System.IO.Directory]::GetDirectories("$(SolutionDirectory)","bin", SearchOption.AllDirectories))" />
<BinDirs Remove="$(MyDirectory)\%(ExcludedDirs.Identity)\**" />
</ItemGroup>
Now all bin diretoreis are in BinDirs, however, the bin directories in ext and lib are not excluded. What's the solution?