views:

237

answers:

2

I want to recursively delete files that match a certain pattern as part of my post-build cleanup routines in TFS Build. I've tried this...

<Delete Files="T:\DeploymentDir\**\A*" />

No errors in the build, but it doesn't work.

+1  A: 

I don't think the Delete task will automatically expand the wildcard. You'll need to specify an itemgroup first, then pass that into the Delete task:

<ItemGroup>
  <FilesToDelete Include="T:\DeploymentDir\**\A*"/>
</ItemGroup>

<Delete Files="@(FilesToDelete)"/>

With MSBuild 3.5 onwards you can include the ItemGroup in the same target as the Delete task.

Ross Johnston
+1  A: 

Modify your TFSBuild.proj file and add the following lines at the very end (just before closing ):

<Target Name="AfterDropBuild">
<ItemGroup>
   <FilesToDelete Include="$(DropLocation)\$(BuildNumber)\**\temp*.*" />
</ItemGroup> 

<Delete Files="@(FilesToDelete)" TreatErrorsAsWarnings="true"/>
</Target>
Nikhil Singhal