1:先建立一个类库项目
2:类文件一个内容如下
- using System;
- using System.Collections;
- using System.ComponentModel;
- using System.Configuration.Install;
- using System.IO;
- using System.Diagnostics;
- using System.Windows.Forms;
- namespace install
- {
- /// <summary>
- /// Installer1 的摘要说明。
- /// </summary>
- [RunInstaller(true)]
- public class Installer1 : System.Configuration.Install.Installer
- {
- /// <summary>
- /// 必需的设计器变量。
- /// </summary>
- private System.ComponentModel.Container components = null;
- public Installer1()
- {
- // 该调用是设计器所必需的。
- InitializeComponent();
- // TODO: 在 InitializeComponent 调用后添加任何初始化
- }
- /// <summary>
- /// 清理所有正在使用的资源。
- /// </summary>
- protected override void Dispose(bool disposing)
- {
- if (disposing)
- {
- if (components != null)
- {
- components.Dispose();
- }
- }
- base.Dispose(disposing);
- }
- public override void Commit(IDictionary savedState)
- {
- base.Commit(savedState);
- try
- {
- //Process process = new Process();
- //process.StartInfo.FileName = "msiexec";
- //process.StartInfo.UseShellExecute = true;
- //process.StartInfo.WorkingDirectory = this.Context.Parameters["targetdir"].ToString();
- MessageBox.Show("fef:"+this.Context.Parameters["targetdir"].ToString());
- //process.StartInfo.Arguments = @"/i plus.msi /passive";
- //process.Start();
- MessageBox.Show("123");
- }
- catch (Exception e)
- {
- throw new InstallException(e.ToString());
- }
- }
- #region 组件设计器生成的代码
- /// <summary>
- /// 设计器支持所需的方法 - 不要使用代码编辑器修改
- /// 此方法的内容。
- /// </summary>
- private void InitializeComponent()
- {
- components = new System.ComponentModel.Container();
- }
- #endregion
- }
- }
然后在setup项目里面自定义安装的各处都添加项目输出来自于该项目
Context.Parameters["targetdir"] 中的值设置如下
setup自定义操作中添加的上面的安装类库的项目输出--属性-CustomActionData 设置为 /targetdir="[TARGETDIR]/"
=========================
重要的地方是System.Configuration.Install.Installer这个类的重写
也可以勾挂事件,另外需要手动在项目中引用该dll