Simple example of a custom .net installer using the path of the installed app
I simply want to create a custom installer to run code after installation which requires the path of the installed application.
I read about how to create a custom installer and Custom Actions, as well as what properties are available in the installer, but I don't quite get how to access those properties from inside the custom installer code. (Don't even get me started on the complexity of Windows Installer documentation.)
The best answer would be full code for a custom installer using the app path. This 开发者_运维问答is what I've got so far:
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);
}
}
}
}
Guess I've got to do everything myself (sigh) ;-)
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);
}
}
}
}
精彩评论