Click here to Skip to main content
12,509,932 members (58,743 online)
Click here to Skip to main content
Add your own
alternative version

Stats

172.5K views
1.2K downloads
59 bookmarked
Posted

Steps for creating Custom Setup

, 27 Sep 2005
Rate this:
Please Sign up or sign in to vote.
If you ever thought creating a custom setup should be an easy task, here are the tips to break the ice.

Introduction

This is the article I wanted to find when I first began creating my custom setup. The information that I could find was broken in pieces and spread over the World Wide Web. I could only rely on parts of the algorithm and it took my precious time to figure out the actual business flow. That's why I finally decided to write this synthesis. The battle is in the custom actions and user interface sections. How do I configure a UI dialog and how can I hook the information entered in one of these dialogs to a piece of code that will do the custom configuration I want, based on this information?????

Here is an easy way to do this:

The main flow

Step 1

The best practice is to create a brand new assembly for creating personal customized steps while running the installer, namely InstallHelper-s.

Step 2

Choose your strategy:

Strategy 1

Create a console application project (I named it as InstallHelperVers1) and expect customized values in the args[] array of InstallHelperVers1 main entry point:

/// <SUMMARY>
/// The main entry point for the application.
/// </SUMMARY>
[STAThread]
static void Main(string[] args)
{
    string sz1 = args[0];
    string sz2 = args[1];

    Console.WriteLine("First option = " + sz1);
    Console.WriteLine("Second option = " + sz2);
}

Build the project and add it to the file system section. Add a custom action by choosing the InstallHelperVers1application. Open the Properties window of the newly added assembly and fill in the arguments section using "[" and "]" characters. The custom dialog field values are as follows:

where EDITA1 and EDITA2 are what you previously configured in the custom dialog textboxes in the Properties window at the Edit1Property and Edit2Property. You can leave the rest of the properties with their default values.

Results: While installing, InstallHelperVers1 will be executed with the mentioned arguments.

Strategy 2

Create a class library application project (I named it as InstallHelperVers2). Add a new item and choose an Installer class:

Override the OnBeforeInstall event or a more suitable event to serve your interest. Here is the MSDN example of how to do it:

using System;
using System.Collections;
using System.ComponentModel;
using System.Configuration.Install;

// Set 'RunInstaller' attribute to true.
[RunInstaller(true)]
public class MyInstallerClass: Installer
{
   public MyInstallerClass() :base()
   {
      // Attach the 'Committed' event.
      this.Committed += new InstallEventHandler(MyInstaller_Committed);
      // Attach the 'Committing' event.
      this.Committing += new InstallEventHandler(MyInstaller_Committing);

   }
   // Event handler for 'Committing' event.
   private void MyInstaller_Committing(object sender, InstallEventArgs e)
   {
      Console.WriteLine("");
      Console.WriteLine("Committing Event occured.");
      Console.WriteLine("");
   }
   // Event handler for 'Committed' event.
   private void MyInstaller_Committed(object sender, InstallEventArgs e)
   {
      Console.WriteLine("");
      Console.WriteLine("Committed Event occured.");
      Console.WriteLine("");
   }
   // Override the 'Install' method.
   public override void Install(IDictionary savedState)
   {
      base.Install(savedState);
   }
   // Override the 'Commit' method.
   public override void Commit(IDictionary savedState)
   {
      base.Commit(savedState);
   }
   // Override the 'Rollback' method.
   public override void Rollback(IDictionary savedState)
   {
      base.Rollback(savedState);
   }
   public static void Main()
   {
      Console.WriteLine("Usage : installutil.exe Installer.exe ");
   }
}

Expect customized values in the Context.Parameters.Keys array. Build the project and add it to the file system section. Add a custom action by choosing the InstallHelperVers2 application. Open the Properties window for the newly added assembly and fill in the CustomActionData section using the "[" and "]" characters to specify a field and a "/" character to specify each parameter. The custom dialog field values are as follows:

where e1 and e2 are the keys you address from your Installer class: string firstEdit = Context.Parameters["e1"];, and EDITA1 and EDITA2 are what you have previously configured in the custom dialog textboxes in the Properties window at the Edit1Property and Edit2Property, as you can see below:

If you want to see the parameters (typed or customized) that are available for use, use this code:

foreach (string keyValue in Context.Parameters.Keys)
{
  Console.WriteLine(keyValue + " = " + Context.Parameters[keyValue]);
}

It is highly important in this case to set the InstallerClass to TRUE. You can leave the rest of the properties with their default values.

Results: While installing, InstallHelperVers2 will be executed. Spot the Installer class and execute whatever is overridden in your Installer class.

Strategy 3

Repeat the steps from Strategy 2 with a few changes: Create InstallHelperVers3 as a simple Windows application project. Add an Installer class into this project. Forget all about setup dialogs and use the minimum possible dialogs in the setup project, the main and recommended ones are: Welcome dialog and installation folder dialog (and maybe customer information dialog).

For the rest of your customized steps, just follow the flow given below:

  1. Create a trycatch … transaction in your Installer class; use the catch section to rollback installation if everything goes wrong.
  2. Create a simple Windows Forms in your InstallHelper project that respects the setup main flow (Back and Previous buttons, Commit methods, etc.).
  3. Invoke these forms from inside the try section.
  4. Don't use any parameters when invoking this build during installation as you have transferred the whole business inside the InstallHelper.

Results: While installing, InstallHelperVers3 will be executed. Spot the Installer class and execute whatever is overridden in your Installer class, and that is your own setup flow.

That's it! As simple as that! From now on, use your imagination to complicate this scenario.

Good luck!

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

Gelu Vac
Romania Romania
No Biography provided

You may also be interested in...

Pro
Pro

Comments and Discussions

 
QuestionHow to validate thing Pin
adit_sheth25-May-12 8:59
memberadit_sheth25-May-12 8:59 
GeneralMy vote of 1 Pin
Robert detoi26-Nov-11 21:13
memberRobert detoi26-Nov-11 21:13 
GeneralYour Artcle is very Difficult to Follow Pin
Vuyiswa Maseko22-Jan-09 2:16
memberVuyiswa Maseko22-Jan-09 2:16 
QuestionHow to Hide the setup when the Form1(Custom exe) is opened? Pin
Nagendran23-Dec-08 22:34
memberNagendran23-Dec-08 22:34 
GeneralThank Goodness! Pin
D_Friendly_Bear22-Aug-07 19:12
memberD_Friendly_Bear22-Aug-07 19:12 
QuestionEnable/disable - Next/Back buttons on custom dialogs? Pin
Preky19-Jul-07 2:51
memberPreky19-Jul-07 2:51 
GeneralNeed Help for Custom dialog of 3 checknox button Pin
Patel Pranav15-Feb-07 1:14
memberPatel Pranav15-Feb-07 1:14 
GeneralRe: Need Help for Custom dialog of 3 checknox button Pin
Gelu Vac15-Feb-07 2:57
memberGelu Vac15-Feb-07 2:57 
QuestionCustom Actions without default installer class Pin
JimDotNet19-Jul-06 3:51
memberJimDotNet19-Jul-06 3:51 
AnswerRe: Custom Actions without default installer class Pin
Danieliw5-Jan-07 3:40
memberDanieliw5-Jan-07 3:40 
GeneralSetup Project in VisualStudio.NET(2003) Pin
rishim24619-Mar-06 1:25
memberrishim24619-Mar-06 1:25 
QuestionHow to cancel (rollback) setup Pin
Kukurice6-Dec-05 3:43
memberKukurice6-Dec-05 3:43 
AnswerRe: How to cancel (rollback) setup Pin
Gelu Vac6-Dec-05 20:30
memberGelu Vac6-Dec-05 20:30 
GeneralRe: How to cancel (rollback) setup Pin
Kukurice13-Dec-05 3:50
memberKukurice13-Dec-05 3:50 
GeneralRe: How to cancel (rollback) setup Pin
abhinish2-Aug-06 1:40
memberabhinish2-Aug-06 1:40 
GeneralRe: How to cancel (rollback) setup Pin
Kukurice3-Aug-06 7:47
memberKukurice3-Aug-06 7:47 
AnswerRe: How to cancel (rollback) setup Pin
JonCL3-Aug-06 9:05
memberJonCL3-Aug-06 9:05 
GeneralRe: How to cancel (rollback) setup Pin
Mohammed Owais1-Aug-14 19:37
professionalMohammed Owais1-Aug-14 19:37 
QuestionCommand line Pin
Kikoz6822-Oct-05 16:19
memberKikoz6822-Oct-05 16:19 
Generalfew little problems Pin
Josh Furcoat6-Oct-05 19:23
memberJosh Furcoat6-Oct-05 19:23 
GeneralRe: few little problems Pin
Gelu Vac6-Oct-05 22:12
memberGelu Vac6-Oct-05 22:12 
QuestionHow to validate serial number Pin
PCKH19776-Oct-05 1:23
memberPCKH19776-Oct-05 1:23 
AnswerRe: How to validate serial number Pin
Gelu Vac6-Oct-05 23:52
memberGelu Vac6-Oct-05 23:52 
GeneralRe: How to validate serial number Pin
Mukund Pujari18-Jan-06 22:11
memberMukund Pujari18-Jan-06 22:11 
GeneralRe: How to validate serial number Pin
Gelu Vac19-Jan-06 20:47
memberGelu Vac19-Jan-06 20:47 
GeneralRe: How to validate serial number Pin
Mukund Pujari22-Jan-06 17:11
memberMukund Pujari22-Jan-06 17:11 
GeneralRe: How to validate serial number Pin
Gelu Vac22-Jan-06 21:29
memberGelu Vac22-Jan-06 21:29 
GeneralRe: How to validate serial number Pin
Mukund Pujari22-Jan-06 21:57
memberMukund Pujari22-Jan-06 21:57 
GeneralRe: How to validate serial number Pin
manopoty201210-Mar-10 15:00
membermanopoty201210-Mar-10 15:00 
GeneralGood article but problem in installing setup file Pin
Sreenath Madyastha27-Sep-05 11:09
memberSreenath Madyastha27-Sep-05 11:09 
GeneralRe: Good article but problem in installing setup file Pin
Gelu Vac27-Sep-05 20:39
memberGelu Vac27-Sep-05 20:39 
GeneralRe: Good article but problem in installing setup file Pin
Sreenath Madyastha28-Sep-05 5:24
memberSreenath Madyastha28-Sep-05 5:24 
GeneralRe: Good article but problem in installing setup file Pin
Gelu Vac28-Sep-05 20:14
memberGelu Vac28-Sep-05 20:14 
GeneralGreat article, great article Pin
Zorba Grecu22-Sep-05 23:45
sussZorba Grecu22-Sep-05 23:45 
GeneralRe: Great article, great article Pin
Sreenath Madyastha27-Sep-05 11:08
memberSreenath Madyastha27-Sep-05 11:08 
GeneralRe: Great article, great article Pin
windrago27-Sep-05 17:11
memberwindrago27-Sep-05 17:11 
GeneralRe: Great article, great article Pin
Sreenath Madyastha28-Sep-05 5:27
memberSreenath Madyastha28-Sep-05 5:27 
QuestionImages? Pin
aprenot20-Sep-05 5:44
memberaprenot20-Sep-05 5:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    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
Web02 | 2.8.160929.1 | Last Updated 28 Sep 2005
Article Copyright 2005 by Gelu Vac
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid