Custom project installer
i want to create own custom installer for web project.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
krishna kanhaiya191 reputationPosted Nov 10, 2016, 11:49 PM EST
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: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
EDITA1andEDITA2are what you previously configured in the custom dialog textboxes in the Properties window at theEdit1PropertyandEdit2Property. 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
OnBeforeInstallevent 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.Keysarray. 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
e1ande2are the keys you address from your Installer class:string firstEdit = Context.Parameters["e1"];, andEDITA1andEDITA2are what you have previously configured in the custom dialog textboxes in the Properties window at theEdit1PropertyandEdit2Property, as you can see below:If you want to see the parameters (typed or customized) that are available for use, use this code:
It is highly important in this case to set the
InstallerClasstoTRUE. 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:
try…catch… transaction in your Installer class; use thecatchsection to rollback installation if everything goes wrong.trysection.