My Snippets

Getting a list of subfolders using MSBuild

XML:
  1. <Project DefaultTargets="Test" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  2.     <PropertyGroup>
  3.     </PropertyGroup>
  4.  
  5.     <Target Name="Test">
  6.         <Message Text="List my subdirectory names (not the files)"/>
  7.        
  8.         <CallTarget Targets="CreateTopLevelDirProperty" />
  9.         <CallTarget Targets="CreateMyList" />
  10.         <CallTarget Targets="CreateMySubDirsList" />
  11.         <CallTarget Targets="ProcessMySubDirsList" />
  12.     </Target>
  13.  
  14.   <Target Name="CreateTopLevelDirProperty">
  15.         <CreateProperty Value="C:\Program Files\Pulte\MSBuild">
  16.             <Output TaskParameter="Value" PropertyName="TopLevelDir" />
  17.         </CreateProperty>
  18.   </Target>
  19.  
  20.   <Target Name="CreateMyList">
  21.     <CreateItem Include="$(TopLevelDir)\*\**">
  22.       <Output ItemName="MyList" TaskParameter="Include"/>
  23.     </CreateItem>
  24.   </Target>
  25.  
  26.   <Target Name="CreateMySubDirsList">
  27.     <CreateItem Include="%(MyList.RelativeDir)">
  28.       <Output ItemName="MySubDirs" TaskParameter="Include"/>
  29.     </CreateItem>
  30.   </Target>
  31.  
  32.   <Target Name="ProcessMySubDirsList">
  33.         <Message Text="Subdir: %(MySubDirs.Identity)"/>
  34.   </Target>
  35. </Project>

August 29th, 2008 Posted by | msbuild | no comments

No Comments

No comments yet.

Sorry, the comment form is closed at this time.