zoukankan      html  css  js  c++  java
  • .net 自带打包程序类的写法

    一个打包程序setup.exe,要想在安装或卸载之间进行其它操作,需要如下操作。

    首先建立一个类库:  

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Linq;
    using System.Text;
    using System.Configuration.Install; //引用此命名空间

    namespace myInstall
    {

     
        [RunInstaller(true)] //序列话,否则无法运行到此程序
        public class Installer1 : Installer //首先继承Installer类
        {

       // 自定义的方法,需要做的事情
            private void InstallDateBase()
            {

                System.Reflection.Assembly Asm;

                Asm = System.Reflection.Assembly.GetExecutingAssembly();

                System.IO.FileInfo FileInfo = new System.IO.FileInfo(Asm.Location.Substring(0, Asm.Location.LastIndexOf("\\") + 1));

                ProcessStartInfo psi = new ProcessStartInfo();

                psi.FileName = FileInfo.FullName +"Install.bat";//  "飞鸽.exe";

                psi.UseShellExecute = true;

                Process.Start(Asm.Location.Substring(0, Asm.Location.LastIndexOf("\\") + 1) + "Install.bat");        

            }

            //在点击安装“完成”之前要执行的一段代码

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

                try
                {

                    base.Install(stateSaver);

                    this.InstallDateBase();//调用上面的方法

                }

                catch
                {

                    throw;

                }

            }

        //卸载完成之前可执行此代码

            public override void Uninstall(System.Collections.IDictionary stateSaver)
            {
                base.Uninstall(stateSaver);
            }

       //在提交时执行代码

            public override void Commit(System.Collections.IDictionary stateSaver)
            {
                base.Commit(stateSaver);

            }

       //回滚时执行代码

            public override void Rollback(System.Collections.IDictionary stateSaver)
            {
                base.Rollback(stateSaver);
            } 
        }
    }

    生成它之后,在setup.exe项目中添加此dll,然后在自定义操作时找到此类,如下图:


     

     

    然后再重新生成setup.exe程序,既可完成需要做的工作。

    若选择第二种方式添加卸载程序,需要设置其快捷方式的Arguments属性值为:/x { E9E37B3F-FB17-4002-89CE-E1210057E6C4}

  • 相关阅读:
    Spring MVC(1)Spring MVC的初始化和流程以及SSM的实现
    Spring(四)Spring与数据库编程
    MyBatis(4)-- 动态SQL
    MyBatis(3)-- Mapper映射器
    MyBatis(2)-- MyBatis配置mybatis-config.xml
    MyBatis(1)-- MyBatis介绍
    计算机网络(2)-- URL、HTTP、HTTPS、HTML
    计算机网络(1)- TCP
    Shell脚本编程
    和为定值的多个数
  • 原文地址:https://www.cnblogs.com/lbg280/p/1644144.html
Copyright © 2011-2022 走看看