我只想创建一个自定义安装程序,以便在安装后运行代码,这需要安装的应用程序的路径.
我读到了如何创建自定义安装程序和自定义操作,以及安装程序中可用的属性,但我不知道如何从自定义安装程序代码中访问这些属性.(甚至不要让我开始了解Windows Installer文档的复杂性.)
最佳答案是使用应用程序路径的自定义安装程序的完整代码.这是我到目前为止所得到的:
using System;
using System.ComponentModel;
namespace Hawk
{
[RunInstaller(true)]
public class Installer : System.Configuration.Install.Installer
{
public Installer()
{
}
public override void Install(System.Collections.IDictionary stateSaver)
{
base.Install(stateSaver);
try
{
//TODO Find out installer path
string path = (string)stateSaver["TARGETDIR"]; // Is this correct?
// Environment.CurrentDirectory; // What is this value?
MyCustomCode.Initialize(path);
}
catch (Exception ex)
{
// message box to show error
this.Rollback(stateSaver);
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我想我必须自己做所有事情(叹气);-)
using System;
using System.ComponentModel;
using System.IO;
namespace Hawk
{
[RunInstaller(true)]
public class Installer : System.Configuration.Install.Installer
{
public override void Install(System.Collections.IDictionary stateSaver)
{
base.Install(stateSaver);
try
{
string assemblyPath = this.Context.Parameters["assemblypath"];
// e.g. C:\Program Files\[MANUFACTURER]\[PROGRAM]\[CUSTOM_INSTALLER].dll
MyCustomCode.Initialize(assemblyPath);
}
catch (Exception ex)
{
//TODO message box to show error
this.Rollback(stateSaver);
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3866 次 |
| 最近记录: |