A simple example of a custom .net installer using the path to an installed application

I just want to create a custom installer to run the code after installation, which requires a path to the installed application.

I read about how to create a custom installer and Custom Actions , as well as the fact that properties are available in the installer , but I don’t quite understand how to access these properties from inside the user installer code. (Do not make me start with the complexity of the Windows Installer documentation .)

The best answer would be the complete code for the custom installer using the application path. This is what I have 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); } } } } 
+4
source share
1 answer

Guess I have 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"]; // eg C:\Program Files\[MANUFACTURER]\[PROGRAM]\[CUSTOM_INSTALLER].dll MyCustomCode.Initialize(assemblyPath); } catch (Exception ex) { //TODO message box to show error this.Rollback(stateSaver); } } } } 
+2
source

Source: https://habr.com/ru/post/1311111/


All Articles