首页 新闻 会员 周边

winform安装部署类System.Configuration.Install.Installer里的函数不执行

0
悬赏园豆:20 [已解决问题] 解决于 2016-07-20 10:40

我有一个winform的程序A,有一个setup的打包安装程序,都可用。后来需求变化,setup打包安装程序无法满足安装时的需求,于是在A里添加了安装类MyInstaller,代码如下:

[RunInstaller(true)]
    public partial class MyInstaller : System.Configuration.Install.Installer
    {
        public MiInstaller()
            : base()
        {
            //InitializeComponent();
            // 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("");
            MessageBox.Show("Committing Event occured.");
        }
        // Event handler for 'Committed' event.
        private void MyInstaller_Committed(object sender, InstallEventArgs e)
        {
            //Console.WriteLine("");
            //Console.WriteLine("Committed Event occured.");
            //Console.WriteLine("");
            MessageBox.Show("Committed Event occured.");
        }
        // Override the 'Install' method.
        public override void Install(IDictionary savedState)
        {
            base.Install(savedState);

            string productName = Context.Parameters["ProductName"].Trim();

            string whateveryouwant = Context.Parameters["whateveryouwant"].Trim();
        }
        // 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 ");
        //    MessageBox.Show("Usage : installutil.exe Installer.exe.");
        //}

        private void MiInstaller_BeforeInstall(object sender, InstallEventArgs e)
        {
            MessageBox.Show("MiInstaller_BeforeInstall");
        }
    }

但是生成出msi安装包之后,在安装的时候不执行里面的函数,一个也没执行。后来google,说是需要添加一个library,把myinstaller弄到library里,在setup打包程序里添加--项目输出--设置library的项目输出,然后在安装那里设置选择libary的主输出,但是build出msi之后,安装依然执行不到myinstaller,这是为什么呢?

就这么多分了,多谢帮忙!

mrhyher的主页 mrhyher | 初学一级 | 园豆:5
提问于:2016-04-27 15:31
< >
分享
最佳答案
0

你别新建类,你在原有的类中写这些代码

收获园豆:20
刘宏玺 | 专家六级 |园豆:14020 | 2016-04-27 15:38

大侠,没明白,原有的类是指什么类?

mrhyher | 园豆:5 (初学一级) | 2016-04-27 15:40

@mrhyher: 就是打包项目中的那个类

刘宏玺 | 园豆:14020 (专家六级) | 2016-04-27 15:41

@刘宏玺: 我才看到,你的类是写在A里了,A项目又不是打包程序,怎么可能有作用呢?

刘宏玺 | 园豆:14020 (专家六级) | 2016-04-27 15:42

@刘宏玺: 我的打包程序是创建的:其他项目类型--安装和部署--visual studio installer,创建好之后里面没有类,只有三个如下图的文件目录操作。

mrhyher | 园豆:5 (初学一级) | 2016-04-27 15:48

@刘宏玺: 是我建错了吗?

mrhyher | 园豆:5 (初学一级) | 2016-04-27 15:53

@mrhyher: 用这个打包项目就不能自定义了,你看下这个

http://blog.csdn.net/swarb/article/details/7074647

刘宏玺 | 园豆:14020 (专家六级) | 2016-04-27 15:54
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册