自定义安装

需求:

现在我想要安装完成一个简单的自定义操作:

1 在安装过程中提供两个文本框,用于我输入数据库服务器名和要打开的数据库名。

2 将我的输入的数据写入一个文本文件,保存在 c:\log.txt。

**实现:
**
1 新建一个类库项目,在该项目下添加一个类:
using System;
using System.ComponentModel;
using System.Collections;
using System.Configuration.Install;
using System.IO;

[RunInstaller(true)]

public class MyInstaller : Installer
{
public override void Install(IDictionary savedState)
{
base.Install(savedState);
try

{

StreamWriter writer = new StreamWriter("c:\\log.txt");

writer.WriteLine("whern i kasdjf" + System.DateTime.Now.ToString());

writer.WriteLine(this.Context.Parameters["Server"] + this.Context.Parameters["Database"]);

writer.Close();

}

catch (Exception e)

{

throw new InstallException(e.Message);

}

}

///

1<summary>
2
3/// Commit is called when install goes through successfully. 
4
5/// </summary>

///

1<param name="savedState"/>

public override void Commit(IDictionary savedState)

{

base.Commit(savedState);

}

///

1<summary>
2
3/// Rollback is called if there is any error during Install. 
4
5/// </summary>

///

1<param name="savedState"/>

public override void Rollback(IDictionary savedState)

{

base.Rollback(savedState);

}

public override void Uninstall(IDictionary savedState)

{

base.Uninstall(savedState);

}

}

2 将类库编译为 MyInstall.dll。

在你安装项目中:

1 进入“用户界面”视图。

a 在启动中添加一个 “文本框C”。

b 将文本框上移到“安装文件夹”之上。

c 设置文本框属性:

Edit3Visible = False

Edit4Visible = False

Edit1Label = “数据库服务器”

Edit2Label = “数据库”

2 进入“自定义操作”视图。

a 在 "安装目录" 下添加程序集 MyInstall.dll。

b 设置 MyInstall.dll 属性:

InstallerClass = True

CustonActionData = /Server=[EDITC1] /Database=[EDITC2]

到这一步就 Ok 了。

参考文档:

Installer Applications and Components (英文)。

安裝時將應用程式重新導向其他的目標 XML Web 服務(繁体)

Published At
Categories with Web编程
Tagged with
comments powered by Disqus