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.
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>
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.
来源:https://stackoverflow.com/questions/2091898/how-to-recursively-delete-wildcard-files-in-tfs-build