Click here to Skip to main content
6,683,239 members and growing! (16,852 online)
Email Password   helpLost your password?
Development Lifecycle » Installation » General     Intermediate

Steps for creating Custom Setup

By Gelu Vac

If you ever thought creating a custom setup should be an easy task, here are the tips to break the ice.
C#, VB, VC8.0, Windows, .NET 1.0, .NET 1.1, .NET 2.0, DotGNU, ASP.NET, WebForms, VS.NET2003, VS2005, Dev
Posted:20 Sep 2005
Updated:27 Sep 2005
Views:97,169
Bookmarked:51 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
17 votes for this article.
Popularity: 4.25 Rating: 3.45 out of 5
5 votes, 29.4%
1
1 vote, 5.9%
2

3
4 votes, 23.5%
4
7 votes, 41.2%
5

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

About the Author

Gelu Vac


Member

Location: Romania Romania

Other popular Installation articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 25 of 34 (Total in Forum: 34) (Refresh)FirstPrevNext
GeneralYour Artcle is very Difficult to Follow PinmemberVuyiswa Maseko3:16 22 Jan '09  
QuestionHow to Hide the setup when the Form1(Custom exe) is opened? PinmemberNagendran23:34 23 Dec '08  
GeneralThank Goodness! PinmemberD_Friendly_Bear20:12 22 Aug '07  
QuestionEnable/disable - Next/Back buttons on custom dialogs? PinmemberPreky3:51 19 Jul '07  
GeneralNeed Help for Custom dialog of 3 checknox button PinmemberPatel Pranav2:14 15 Feb '07  
GeneralRe: Need Help for Custom dialog of 3 checknox button PinmemberGelu Vac3:57 15 Feb '07  
QuestionCustom Actions without default installer class PinmemberJimDotNet4:51 19 Jul '06  
AnswerRe: Custom Actions without default installer class PinmemberDanieliw4:40 5 Jan '07  
GeneralSetup Project in VisualStudio.NET(2003) Pinmemberrishim2462:25 19 Mar '06  
GeneralHow to cancel (rollback) setup PinmemberKukurice4:43 6 Dec '05  
GeneralRe: How to cancel (rollback) setup PinmemberGelu Vac21:30 6 Dec '05  
GeneralRe: How to cancel (rollback) setup PinmemberKukurice4:50 13 Dec '05  
GeneralRe: How to cancel (rollback) setup Pinmemberabhinish2:40 2 Aug '06  
GeneralRe: How to cancel (rollback) setup PinmemberKukurice8:47 3 Aug '06  
AnswerRe: How to cancel (rollback) setup PinmemberJonCL10:05 3 Aug '06  
QuestionCommand line PinmemberKikoz6817:19 22 Oct '05  
Generalfew little problems PinmemberJosh Furcoat20:23 6 Oct '05  
GeneralRe: few little problems PinmemberGelu Vac23:12 6 Oct '05  
QuestionHow to validate serial number PinmemberPCKH19772:23 6 Oct '05  
AnswerRe: How to validate serial number PinmemberGelu Vac0:52 7 Oct '05  
GeneralRe: How to validate serial number PinmemberMukund Pujari23:11 18 Jan '06  
GeneralRe: How to validate serial number PinmemberGelu Vac21:47 19 Jan '06  
I have already developed an entire solution in VB.Net for Kumara on license validation and have sent it to him at no cost.
It took me few days to entierly build it in VB.Net, I don't have that solution nomore, as VB is not of my interest - I am an ex-Visual C++ professional developer and I currenty work with C#.
So please contact Kumara and ask him for it.
You should understand that License validation is a whole architectural issue, and can be done multiple ways, depending on what exactely do you want to do.
One tip is to pack in your installer a collection of valid license numbers, then apply Strategy number 3 from my Custom Install article.
Applying this strategy, you should know that the execution of the Install of AfterInstall overrided event takes place after installer files deployment, so that you will have access to the physical files at that moment.
I hope this helps!
Have luck!
Sign In·View Thread·PermaLink
GeneralRe: How to validate serial number PinmemberMukund Pujari18:11 22 Jan '06  
GeneralRe: How to validate serial number PinmemberGelu Vac22:29 22 Jan '06  
GeneralRe: How to validate serial number PinmemberMukund Pujari22:57 22 Jan '06  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 27 Sep 2005
Editor: Genevieve Sovereign
Copyright 2005 by Gelu Vac
Everything else Copyright © CodeProject, 1999-2009
Web22 | Advertise on the Code Project