自定义安装部署包

1:先建立一个类库项目

2:类文件一个内容如下

  1. using System;
  2. using System.Collections;
  3. using System.ComponentModel;
  4. using System.Configuration.Install;
  5. using System.IO;
  6. using System.Diagnostics;
  7. using System.Windows.Forms;
  8. namespace install
  9. {
  10.     /// <summary>
  11.     /// Installer1 的摘要说明。
  12.     /// </summary>
  13.     [RunInstaller(true)]
  14.     public class Installer1 : System.Configuration.Install.Installer
  15.     {
  16.         /// <summary>
  17.         /// 必需的设计器变量。
  18.         /// </summary>
  19.         private System.ComponentModel.Container components = null;
  20.         public Installer1()
  21.         {
  22.             // 该调用是设计器所必需的。
  23.             InitializeComponent();
  24.             // TODO: 在 InitializeComponent 调用后添加任何初始化
  25.         }
  26.         /// <summary> 
  27.         /// 清理所有正在使用的资源。
  28.         /// </summary>
  29.         protected override void Dispose(bool disposing)
  30.         {
  31.             if (disposing)
  32.             {
  33.                 if (components != null)
  34.                 {
  35.                     components.Dispose();
  36.                 }
  37.             }
  38.             base.Dispose(disposing);
  39.         }
  40.         public override void Commit(IDictionary savedState)
  41.         {
  42.             base.Commit(savedState);
  43.             try
  44.             {
  45.                 //Process process = new Process();
  46.                 //process.StartInfo.FileName = "msiexec";
  47.                 //process.StartInfo.UseShellExecute = true;
  48.                 //process.StartInfo.WorkingDirectory = this.Context.Parameters["targetdir"].ToString();
  49.                 MessageBox.Show("fef:"+this.Context.Parameters["targetdir"].ToString());
  50.                 //process.StartInfo.Arguments = @"/i plus.msi /passive";
  51.                 //process.Start();
  52.                 MessageBox.Show("123");
  53.             }
  54.             catch (Exception e)
  55.             {
  56.                 throw new InstallException(e.ToString());
  57.             }
  58.         }
  59.         #region 组件设计器生成的代码
  60.         /// <summary>
  61.         /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  62.         /// 此方法的内容。
  63.         /// </summary>
  64.         private void InitializeComponent()
  65.         {
  66.             components = new System.ComponentModel.Container();
  67.         }
  68.         #endregion
  69.     }
  70. }

 

然后在setup项目里面自定义安装的各处都添加项目输出来自于该项目

Context.Parameters["targetdir"] 中的值设置如下

setup自定义操作中添加的上面的安装类库的项目输出--属性-CustomActionData 设置为 /targetdir="[TARGETDIR]/"

 

 

=========================

重要的地方是System.Configuration.Install.Installer这个类的重写

也可以勾挂事件,另外需要手动在项目中引用该dll

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值