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.
<PropertyGroup>
<DeployPath>\\MikesServer\Websites\TestWebsite</DeployPath>
</PropertyGroup>
<Target Name="AfterDropBuild" >
<CreateItem Include="$(DeployPath)\**\*.*" Exclude="$(DeployPath)\**\Web.Config">
<Output ItemName="PreviousDeployment" TaskParameter="Include" />
</CreateItem>
<Delete Files="@(PreviousDeployment)" ContinueOnError="true" />
</Target>
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.