.net 自带打包程序类的写法
2010-01-11 15:24
183 查看
一个打包程序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}
首先建立一个类库:
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}
相关文章推荐
- 图文并茂之.NET程序打包安装与卸载详细教程
- [.Net码农](转)图解WPF程序打包全过程
- .net DLL程序集中打包另一个DLL
- .Net程序打包安装与卸载制作 ——问题描述(一)
- 关于.net web项目打包安装程序安装未完成
- InstallShield Limited Edition for Visual Studio 2013 图文教程(教你如何打包.NET程序)
- .net打包/C#WinFrom程序打包/图解.net打包/.net安装部署图解/VS2008项目的安装与部署图解
- InstallShield Limited Edition for Visual Studio 2013 图文教程(教你如何打包.NET程序)
- 【.Net码农】安装程序打包MFC(visual studio安装部署详解)Install Application Package by using visual studion 2010
- VS自带程序打包部署发布
- 不用VS自带的打包工具,不用InstallShield。用C#自己制作安装程序
- InstallShield Limited Edition for Visual Studio 2013 图文教程(教你如何打包.NET程序)
- .Net程序打包安装与卸载制作 ——怎样制作.Net卸载程序?
- InstallShield Limited Edition for Visual Studio 2013 图文教程(教你如何打包.NET程序)
- .Net程序打包安装与卸载制作 ——怎样将.Net程序部署到没有安装.Net Framwork的机器上?(二)
- 【新手】单机环境下打包.net安装程序
- .Net程序打包安装与卸载制作 ——怎样制作.Net卸载程序?
- (C#)如何用.NET的安装项目打包程序?
- InstallShield Limited Edition for Visual Studio 2013 图文教程(教你如何打包.NET程序)
- InstallShield Limited Edition for Visual Studio 2013 图文教程(教你如何打包.NET程序)