JG Vimalan's Blog

It is all about coding!

Custom actions in .NET installer

I got a task where, I need to perform custom actions right after installing the .NET application. It can be any action, say, write to log file, open the installed application, etc., In order to achieve this, follow the steps given below,

a. In my example I am using a .NET windows forms application. Add a class in your .NET application and inherit it from the System.Configuration.Install.Installer class. The Installer class exposes several useful events. I am performing a custom action in the committed event. Please find the complete code below,

    public class CustomInstaller:System.Configuration.Install.Installer
        public CustomInstaller():base()
            this.Committed += new InstallEventHandler(CustomInstaller_Committed);

        void CustomInstaller_Committed(object sender, InstallEventArgs e)
     //put your code here      
            //this code will run after installation is committed

        public override void Install(System.Collections.IDictionary stateSaver)

        public override void Commit(System.Collections.IDictionary savedState)

        public override void Uninstall(System.Collections.IDictionary savedState)

b. Also, you need to specify the ‘Primary output’ in the custom actions section of your Installer project. To do that, right click your Installer project, View -> Customer Actions. You will be able to see folders like, Install, Commit, Rollback and Uninstall. Now, right click the Commit folder, select custom actions. A dialog will appear. Now, select Application folder and select Primary output. The output will be as shown below,

So, when you install your .net application, finally, your code will run.


November 12, 2010 - Posted by | C#.NET, Windows Forms

1 Comment »

  1. thanks for this post. can you post example for each event in Installer class… that will be helpful…

    Comment by Kumar | November 12, 2010 | Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: