Visual-studio – Need a “post clean event” in Visual Studio

visual studiovisual studio 2010

I got a VS project with a post-build event with a command-line command that copies a file (.dll) to the bin target dir (debug or release). When I do a "Clean" on the project every thing is cleaned, but this file remains. Is there a way to ad post-clean events so I can delete this file also?

Best Answer

You can edit the project file directly and add the target to the end of the file. BeforeClean and AfterClean are targets as explained here:

https://docs.microsoft.com/en-us/visualstudio/msbuild/how-to-extend-the-visual-studio-build-process?view=vs-2019

You should be able to put a Delete task in the target.

EDIT Just tested this (right-click project -> unload -> right click -> edit) and the following target is what you need:

<Target Name="AfterClean">
    <Delete Files="$(TargetDir)\*.txt" />
</Target>

This works when you clean the project but not the solution - it works but not 100%.