In our build process, for each project we use Post Build events to copy our executable files into a separate deployment directory. That works just peachy, but the problem i
For Visual C++ projects, you need to add the files to the "Extensions to Delete On Clean" section under the "General" project configuration properties. Even though it claims to want extensions, it's actually using globs and will happily accept full paths and expand MSBuild variables. This worked for me:
$(ProjectDir)\deployment\*.*
I'm not sure if you can remove directories this way, but it can at least get the files.
The others didn't do exactly what I wanted, and I just found a better way. Tested in VS2010 for a C++ Win32 project, go to Project Properties --> Configuration Properties --> Custom Build Setup. You can add a custom command line, and tell VS what operation to execute the command before or after.
There is no documented way to insert custom cleanup steps, unfortunately. You can clean up your output in your pre-build event but that will still leave artifacts around just after a clean.
From MSDN, here is the order of invocation for the various build steps:
Post-Build event
MSDN: Understanding custom build steps
You can use the MSBuild target syntax in your csproj file. e.g
<Target Name="AfterClean">
<Delete Files="$(OutDir)\$(TargetName).exe" ContinueOnError="true" />
</Target>
There is a neat way to edit your .csproj file directly in the Visual Studio IDE described in the MSBuild team blog, but this is my first post so I can only include one hyperlink. (briefly: Unload the project, then right-click on it to see the entry "Edit [project].csproj" ... your csproj will come up in the IDE as an xml file with intellisense on elements and attributes. Wonderful!)
A full list of custom Targets is here.
You will need to edit the .csproj files by hand and add an "AfterClean" target.
If you use "Project Properties --> Configuration Properties --> Custom Build Setup" you have to remember to fill in the 'Outputs' field, otherwise the it won't run.
from:
http://blogs.msdn.com/b/visualstudio/archive/2010/04/26/custom-build-steps-tools-and-events.aspx
"The Outputs property is a semicolon-delimited list of files, and must list whatever files are generated as part of the execution of your custom build step. If you leave your Outputs property empty, your Custom Build Step will never execute, since MSBuild will determine that no outputs are out of date. If your step doesn’t generate files but you still want it to execute with every build, making up a fake filename will do the trick, since that file will never exist and MSBuild will always determine that the custom build step is out of date."