当前位置导航:炫浪网>>网络学院>>网页制作>>ASP.NET教程

InstallerTest VS部署示例

欢迎进入.NET社区论坛,与200万技术人员互动交流 >>进入

        主要方法,建立一个类库,也就是dll,然后建立一个class,例如MyInstallerClass,必须从Installer继承,同时必须设置[RunInstaller(true)]

        把这个类库添加到安装项目中

        然后在安装项目中右键,选择视图--〉自定义操作,在自定义操作中的安装右键,添加自定义操作,然后指定到这个类库即可。

        卸载、会滚亦然。

        附:

        资源下载:http://download.csdn.net/source/533311

        Installer代码示例:

        using System;
        using System.Collections.Generic;
        using System.Linq;
        using System.Text;
        using System.Collections;
        using System.ComponentModel;
        using System.Configuration.Install;
        namespace ClassLibrary1
        {
            [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)
                {
                    Form1 hc = new Form1();
                    hc.ShowDialog();
                    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 ");
                }
            }
        }

相关内容
赞助商链接