You have to use Custom Actions for that:
- Add a new library ("CustomActions") to the setup project
- Add => New Item => Installer class
- Switch to code view and override the Uninstall method
Code:
public override void Uninstall(IDictionary savedState)
{
base.Uninstall(savedState);
// Delete folder here.
}
If you don't want to write your own DeleteFolder method add a reference to Microsoft.VisualBasic:
Microsoft.VisualBasic.FileIO.FileSystem.DeleteDirectory("C:\\MyFiles", Microsoft.VisualBasic.FileIO.DeleteDirectoryOption.DeleteAllContents);
- Add the project output (Primary Output) of the CustomActions project to the setup project.
- Right click your setup project and click View => Custom Actions
- Rigth click uninstall => Add Custom Action => Application Folder => Primary Output of CustomActions