MSBuild Task syntax for deleting files

Chris Marisic picture Chris Marisic · Sep 25, 2009 · Viewed 53.9k times · Source

I'm trying to write a MSBuild Task that deletes the Obj directory and PDBs from my bin folder on my production build scripts and can't seem to get it to work right.

Does anyone have an example where they do this or similar, or a link to a simple example of removing files and a directory with MSBuild?

Answer

Sayed Ibrahim Hashimi picture Sayed Ibrahim Hashimi · Sep 27, 2009

You can delete the files in those directories first and then the dir itself with

<Target Name="SomeTarget">
    <ItemGroup>
        <FilesToDelete Include="Path\To\Obj\**\*"/>
    </ItemGroup>   
    <Delete Files="@(FilesToDelete)" />   
    <RemoveDir Directories="Path\To\Obj\" />
</Target>