I have a Plugins directory in a Visual Studio project. I would like to delete all files from it when I clean.
Here is how I did this:
- Edit the .csproj file.
- Add the following to the very bottom of the .csproj file, just above the terminating </Project> tag.
<Target Name="afterClean"> <ItemGroup> <FilesToDelete Include="Plugins\**\*"/> </ItemGroup> <Delete Files="@(FilesToDelete)" /> </Target>
- Save the .csproj file.
That should do it.
You should be aware that when doing a custom clean, that in Visual Studio choosing Clean and then Build in two steps is not the same as doing Rebuild.
Clean <-- Cleans all projects Build <-- Builds all projects Rebuild <-- For each project, clean the project, then rebuild the project.So Rebuild is a huge problem and here is why: Since my code is pretty decoupled, my plugins don't reference the project hosting the plugins. So there is not dependency to guarantee the plugin-hosting project cleans and builds first. So when running reubild, a plugin might clean and build and then copy its files to the plugin directory. This could happen before the plugin-hosting project cleans and builds. So you can imagine that once the plugin-hosting project cleans and builds, the newly copied plugin files are cleaned. To fix this, I had to manually add a dependency or just not use Rebuild.