Chris Arnold
Chris Arnold

Reputation: 5753

How to Recursively Delete wildcard files in TFS Build?

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.

Upvotes: 2

Views: 2880

Answers (2)

Nikhil Singhal
Nikhil Singhal

Reputation: 31

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>

Upvotes: 3

Ross Johnston
Ross Johnston

Reputation: 368

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.

Upvotes: 1

Related Questions