使用已安装应用程序路径的自定义.net安装程序的简单示例

Pat*_*Pat 5 .net installer

我只想创建一个自定义安装程序,以便在安装后运行代码,这需要安装的应用程序的路径.

我读到了如何创建自定义安装程序自定义操作,以及安装程序中可用的属性,但我不知道如何从自定义安装程序代码中访问这些属性.(甚至不要让我开始了解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)

Pat*_*Pat 3

我想我必须自己做所有事情(叹气);-)

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)