Geeks With Blogs

(Amazon Affiliate Ads)

Mike Parks Code.Where(c => c.IsTechnicalDebt).Refactor();
A few days ago I needed to delete all files except for web.configs out of a deployment folder using Team Build.  I added the code below to the build definitions .proj file.  It's a quick and easy way to clean out some, but not all, of the files in the deployment folder. You can use wildcards in the CreateItem tag.  It's not perfect because it isn't made to deal with deleting empty sub folders but it got the job done for what I needed.




  <Target Name="AfterDropBuild" >

    <CreateItem Include="$(DeployPath)\**\*.*" Exclude="$(DeployPath)\**\Web.Config">

      <Output ItemName="PreviousDeployment" TaskParameter="Include" />


    <Delete Files="@(PreviousDeployment)" ContinueOnError="true" />




There are a few other ways you can clean out a folder. The delete task is the one I used above. An easy way to delete everything is to use the <RemoveDir Directories="$(OutputPath)\dir" /> and <MakeDir Directories="$(OutputPath)\dir" /> tags. You can also use a MSBuild tasks library such as SDC Tasks and use the CleanFolder task to delete everything in a folder. Posted on Monday, August 3, 2009 10:43 PM | Back to top

Comments on this post: Team Build - Delete All Files - Include and Exclude

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © MikeParks | Powered by: