Custom installer for deployment project

custom installer. create a class library project, add the DLL to your installer project.

eg,. converted to C# from http://weblogs.asp.net/rmclaws/archive/2003/11/18/38426.aspx

namespace Installers {
    using Microsoft.Win32;
    using System.Configuration.Install;
    using System.ComponentModel;
    
    
    [RunInstaller(true)]
    public class Installer : System.Configuration.Install.Installer {
        
        // Required by the Component Designer
        private System.ComponentModel.IContainer components;
        
        public Installer() {
            // This call is required by the Component Designer.
            InitializeComponent();
            // Add any initialization after the InitializeComponent() call
        }
        
        // Installer overrides dispose to clean up the component list.
        protected override void Dispose(bool disposing) {
            if (disposing) {
                if (!(components == null)) {
                    components.Dispose();
                }
            }
            base.Dispose(disposing);
        }
        
        // NOTE: The following procedure is required by the Component Designer
        // It can be modified using the Component Designer. 
        // Do not modify it using the code editor.
        [System.Diagnostics.DebuggerStepThrough()]
        private void InitializeComponent() {
            components = new System.ComponentModel.Container();
        }
        
        public override void Install(System.Collections.IDictionary stateSaver) {
            base.Install(stateSaver);
            //  Gets the parameter passed across in the CustomActionData.
            string KeyName = this.Context.Parameters.Item(“Key”);
            string Location = this.Context.Parameters.Item(“Location”);
            if ((KeyName == “”)) {
                throw new InstallException(“The Registry key was not specified. The Registry could not be modified.”);
            }
            if ((Location == “”)) {
                throw new InstallException(“The Path was not specified. The Registry could not be modified.”);
            }
            RegistryKey regKey;
            regKey = Registry.LocalMachine.OpenSubKey(“SOFTWARE\\Microsoft\\.NETFramework\\AssemblyFolders”, true);
            regKey.CreateSubKey(KeyName);
            regKey.SetValue(“”, Location);
            regKey.Close();
        }
        
        public override void Uninstall(System.Collections.IDictionary stateSaver) {
            base.Uninstall(stateSaver);
            //  Gets the parameter passed across in the CustomActionData.
            string KeyName = this.Context.Parameters.Item(“Key”);
            string Location = this.Context.Parameters.Item(“Location”);
            if ((KeyName == “”)) {
                throw new InstallException(“The Registry key was not specified. The Registry could not be modified.”);
            }
            if ((Location == “”)) {
                throw new InstallException(“The Path was not specified. The Registry could not be modified.”);
            }
            RegistryKey regKey;
            regKey = Registry.LocalMachine.OpenSubKey(“SOFTWARE\\Microsoft\\.NETFramework\\AssemblyFolders”, true);
            regKey.DeleteSubKey(KeyName);
            regKey.Close();
        }
    }
}

Advertisements