Click here to Skip to main content
Click here to Skip to main content

All about Installers - Customizing Windows and Web setup projects

, 10 Jan 2004
Rate this:
Please Sign up or sign in to vote.
This article guides how to customize an installer for specific needs of the application.

Introduction

The deployment is an essential part of the application life cycle. All that user wants from self-defined and self-controlled application is that it should be easy to deploy the application and undeploy without any hassles. This article mainly targets at how to customize the installers to satisfy the application needs. More often than not, Installers need customization to do pre/post processing during installation.

Visual Studio provides different ways to create installers. You can create installers for windows and web applications by creating set up or web set up projects. This article assumes that you need to customize an installer using VS set up projects. You will learn how to write an installer, and customize with different windows based on the need, pass parameters to the custom windows, commit/rollback based on the checks.

Installer Class

Creating an installer for the a windows or web project is a fairly simple job. All that you need to do is, open up your project for which you want to create installer, add a Setup and Deployment Project from File -> Add Project -> New Project. You can select the respective template from Templates window. The following code snippets describe based on a web setup project. The setup project contains few editors to based on their requirement. File System Editor is the default editor displayed, it provides interface to add files to the set up. There are two ways to add files to the set up project. Right clicking on Web Application Folder , it gives an option to add project output or file. Choosing Project Output, You get list of all projects in the solution. Select the project in concern, and add Primary output and Content Files. The second way to add files to the web setup project is selecting each file from the Web project and including them in same directory structure as of the web project.

If you want edit Registry during the installation, Registry Editor can be used to add registry keys under the respective node. User Interface Editor lists the different stages of installation and the dialog windows displayed during each stage. Figure 1 displays the User Interface Editor.

Figure 1 : User Interface Editor

The interesting part is adding custom dialog windows during the installation at particular stage. Right clicking on the Start/Progress/End node and select Add Dialog option. It shows list of predefined windows witch contain Radio Buttons/CheckBoxes/TextBoxes. Though there is not much control over these controls, but these windows allow to disable any particular control (EditVisible property) or provide a default value (EditValue property). The most important property is EditNProperty, using which the value of the control can be accessed when required (like [EditNProperty]). You can change the order of the windows appearing during the installation using move up/down options.

All these windows are predefined and most of the times, they do not fully provide the kind of functionality that most of the applications need. For example, If the installation has to take username/password as input, the default windows cannot be changed to accept password characters. There is an alternative to customize the installation for these kinds of requirements. This can be achieved using Custom Actions Editor. Custom Actions Editor displays four nodes (Install/Commit/Rollback/UnInstall). A custom action can be any action that does some task like running scripts, showing windows or any configuration that needs to be done during the installation. To add custom action, right click on the node, select add custom action option, select any dll/exe file. To make the selected dll/exe act as custom action, we need to make it as an installer as shown below.

[RunInstaller(true)]
public class WebInstaller : System.Configuration.Install.Installer {}

The Run time identifies a class as an installer based on the RunInstaller Attribute (System.ComponentModel). The Installer class that you write needs to be inherited from Installer class in System.configuration.Install namespace. The run time calls Install method of installer class during the installation. This method acts as a starting point for the custom action. To pass parameters to the action, CustomActionData property for the custom action needs to be set with required parameters. The following line shows how to pass virtual directory path and port number to custom action.

Custom Action Data = /VDIR=[TARGETVDIR] /PORT=[TARGETPORT]   /// Note
            //: each parameter needs to separated by a space.

Accessing parameters in Custom Action : Context.Parameters["VDir"] /// Context.Parameters is the collection of the parameters passed.

If custom action fails throw an instance of InstallException. This exception will inform the runtime to rollback the installation.

if (Context.Parameters["VDir"] == null)
{
    throw new InstallException("Virtual directory path not specified");
}

To provide custom dialog windows, add the particular EXE as custom action. The code attached with this article has an exe as custom action. This exe shows a window prompting username/password and tries to connect to sql server. It also updates web.config file with the connectionstring prepared using user input. It also has some cool code to update IIS to turn off anonymous option for the current virtual directory.

Using the code

The demo zip contains a customized installer. It installs web project creating a virtual directory. After installation, it asks for information to update config file and also updates IIS.

The Source zip contains CustomInstall web project, IISInterface project to update IIS, WebSetup project.

Summary

This article caters to the basic requirements of how to customize the installer to show more windows and implement pre/post checks. The key points are creating Custom Actions, passing data to them, aborting installation upon error. Along with these, article also shows how to update config file and IIS settings programmatically.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

avnrao

United States United States
I am working as Senior Software Designer and Developer for last 3.5 years. I like reading tech articles and writing them, mainly .Net stuff.
 
I completed MCAD, MCSD.Net, MCSE-Win2k, MCDBA.

Comments and Discussions

 
Questionusing winform to pass installation path from winform to custom action Pinmemberaditya_ingle3-Nov-12 10:02 
Questionhow to save virtual directory path and port number to registry Pinmemberramamez25-Dec-06 20:31 
QuestionHow To: Get TimeSheetInstaller Code Pinmemberbheinz4-Dec-06 17:18 
GeneralTimesheetInstaller Pinmemberbhavini prajapati12-Oct-06 21:55 
GeneralTimesheetInstaller.exe - solution Pinmemberbdaniel710-Oct-06 1:25 
Generalcode of time sheet project Pinmemberjerome@calcmenu.com24-Aug-06 21:37 
GeneralCustomizing a password field in Web Setup... Pinmemberpetekash24-Aug-06 3:28 
Hi,
 
I want to add a password field in the custom dialog of the VS 2005 Web Setup project. How to do this?? Any ideas are appreciated.
 
Thanks in advance, Peter
GeneralChanging VDIR parameter [modified] Pinmembermarquito_cuba3-Jul-06 8:23 
GeneralTimehseetInstaller Project missing PinmemberDIKIM30-May-06 0:28 
GeneralTimeSheetInstaller Class Pinmemberkesarisuresh18-Oct-05 2:56 
Questionno volume C -easy solution? PinmemberESCOBAR@@@27-Sep-05 16:07 
QuestionSetup Windows en Web Application PinmemberErick J. Tejeda31-Aug-05 10:42 
GeneralTimesheetInstaller project PinmemberAmarendra Modalavalasa29-Aug-05 14:20 
QuestionHow to make items selectable in setup projects? PinmemberTLiu-new12-Aug-05 6:05 
AnswerRe: How to make items selectable in setup projects? PinsussAnonymous12-Aug-05 12:50 
AnswerRe: How to make items selectable in setup projects? Pinmemberraghavagudimetla4-Dec-06 1:56 
GeneralTimesheetinstaller PinmemberAcintha11-Aug-05 23:33 
GeneralRe: Timesheetinstaller PinsussAnonymous12-Aug-05 4:44 
GeneralRe: Timesheetinstaller Pinmemberkalph22-Nov-05 20:26 
Generalputting file in specific folder Pinmemberkadnan15-Mar-05 21:07 
QuestionActions before installing? Pinmemberalforno7-Feb-05 9:47 
GeneralCancel installation outside the custom Install class PinmemberLam Ngoc Nguyen1-Jan-05 6:13 
QuestionDude, where's my file? Pinmemberss__m23-Dec-04 6:49 
AnswerRe: Dude, where's my file? Pinmemberavnrao23-Dec-04 18:08 
GeneralTimeSheetInstaller Project PinmemberAlexBoy18-Nov-04 21:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.141216.1 | Last Updated 11 Jan 2004
Article Copyright 2004 by avnrao
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid