Introduction
This is useful when custom actions are required in the installer while Visual Studio .NET 2003 is used to build the setup using the setup/deployment project.
Background
Visual Studio 2003 does not have an option to add the custom dialogs. It has some predefined dialogs which can be used for any custom actions. If we want to have our own custom dialog, we have to follow the class given below.
Using the Code
This is a generic class which can be used as given here. We need to create a project resulting in a DLL and add this class to the project. Add multiple dialogs required to be launched at the end of the installation.
using System;
using System.Configuration.Install;
using System.ComponentModel;
using System.Collections;
using System.Windows.Forms;
namespace CustomDialogLauncherSpace
{
[RunInstallerAttribute(true)]
public class CustomDialogLauncher : System.Configuration.Install.Installer
{
private string InstallDir;
public CustomDialogLauncher()
{
}
public override void Install(IDictionary savedState)
{
base.Install(savedState);
string TheAssemblyPath = this.Context.Parameters["assemblypath"];
InstallDir = TheAssemblyPath.Substring
(0, TheAssemblyPath.LastIndexOf("\\"));
// Display the custom dialog
// If you want you can use InstallDir else, skip
CustomDialog custDialog = new CustomDialog(InstallDir);
DialogResult result = custDialog.ShowDialog();
if(result != DialogResult.OK)
{
DialogResult rollBack = MessageBox.Show
("This will roll back the installation, are you sure",
"Installation", MessageBoxButtons.YesNo,
MessageBoxIcon.Question);
if(DialogResult.Yes == rollBack)
{
throw new InstallException("Installation aborted, rolling back");
}
}
}
// Overridden Uninstall method which will get called during un install.
public override void Uninstall(IDictionary savedState)
{
base.Uninstall(savedState);
}
// Overridden Rollback method which will get called
// during installation rollback
public override void Rollback(IDictionary savedState)
{
base.Rollback(savedState);
}
public override void Commit(IDictionary savedState)
{
base.Commit(savedState);
}
}
}
Add the multiple custom dialogs required in the setup project in the same project. Call all the dialogs in the Install()
function in the sequence required. Once the new DLL is created, add the DLL to Application folder using Add Custom action. Select the Add file button to add the newly built DLL.
History
- 30th July, 2007: Initial post