添加一个类库项目在里面添加一个安装程序类代码大意如下:
主要目的是自动注册和反注册dll
using System.Collections;
using System.ComponentModel;
using System.Configuration.Install;
using System.Windows.Forms;
namespace Register
{
[RunInstaller(true)]
public partial class RegisterAsm : Installer
{
public RegisterAsm()
{
InitializeComponent();
}
public override void Install(IDictionary stateSaver)
{
try
{
string path = this.Context.Parameters["TargetDir"];
string reTargetFilePath = "/"" + path + "//pulgin.dll/"";
string reFilePath = "/"" + path + "//RegAsm.exe/"";
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = reFilePath; //程序名称
proc.StartInfo.Arguments = reTargetFilePath; //参数
proc.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; //隐藏
proc.Start(); //执行
}
catch (System.Exception)
{
MessageBox.Show("组件自动初测失败,请进行手工注册!");
}
base.Install(stateSaver);
}
public override void Uninstall(IDictionary savedState)
{
try
{
string path = this.Context.Parameters["TargetDir"];
string reTargetFilePath = "/"" + path + "//plugin.dll/"";
string reFilePath = "/"" + path + "//RegAsm.exe /u /"";
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = reFilePath; //程序名称
proc.StartInfo.Arguments = reTargetFilePath; //参数
proc.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; //隐藏
proc.Start(); //执行
}
catch (System.Exception)
{
}
base.Uninstall(savedState);
}
}
}
把这个类添加到输出项目里。。
之后在自定义操作里添加安装和卸载的自定义操作也是用这个类
生成就o啦!
注意事项: (1)自定义操作的customactiondata项一定要注意 /TargetDir="[TARGETDIR]/" 可捕获用户选择的安装路径....
(2)要是打包成.net2.0项目千万记得把启动条件里的框架属性改为2.0的(一般人们容易忽视这里)