My Snippets

Get last element in an XML element list

XML:
  1. <car>
  2.   <wheel name="frontleft">FL</wheel>
  3.   <wheel name="frontright">FR</wheel>
  4.   <wheel name="backleft">BL</wheel>
  5.   <wheel name="backright">BR</wheel>
  6. </car>

xpath: //wheel[last()=position()]
=>

XML:
  1. <wheel name="backright">BR</wheel>

August 29th, 2008 Posted by | xml | no comments
[]

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
[]