Where does the OnAfterInstall event occur?

I had serious problems with how to solve this problem: I do not know where the OnAfterInstall event is going.

Let me explain. I created a C # project that compiles fine and is built in Release mode. After that, I created the installation project using the wizard. I added an additional dialog that allows the user to choose between two languages. Now my problem is that I want to save this language in the registry (or the app.config file is all the easier), and I read that you need to find it in the OnAfterInstall method in the inherited Installer class.

Now where should I put this class? Logic tells me that it goes in a C # project, but it complains that neither the Context class nor the Installer exists. When I add this class to the installation project, it does not complain, but after that it does not work. Here is the class.

using System; using System.Configuration.Install; public class Install : Installer { public Install() { } protected override void OnAfterInstall(IDictionary savedState) { string lang = Context.Parameters["lang"]; RegistryKey key = Registry.LocalMachine; using (key = key.CreateSubKey(@"SOFTWARE\MyCompany\MyApp")) { key.SetValue("lang", lang); key.Close(); } base.OnAfterInstall(savedState); } } 

PS: I already pass lang as CustomActionData using / lang = [LANG] (where LANG is the radio value)

+4
source share
1 answer

First you must add RunInstallerAttribute to your class.

 [RunInstaller(true)] public class Install : Installer ... 

Then put the installer in a separate project (class library), for example. MyCustomInstaller.

Finally, add the main output of this project to the custom action in the custom editor of the installation project.

enter image description here

It's up to you what user action you want to use.

+5
source

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


All Articles