Korcholis Korcholis - 1 month ago 12
C# Question

Where does OnAfterInstall event go?

I've had serious problems on how to solve this: I don't know where the OnAfterInstall event goes.

Let me explain myself. I created a C# project which compiles perfectly and built in Release mode. After that, I've created a Setup Project using the wizard. I have added an extra dialog, which lets the user choose between two languages. Now, my problem is that I want to store that language into the registry (or app.config file, the easier the better), and I've read that you need to detect it within the OnAfterInstall method in an inherited class of Installer.

Now, where should I put that class? Logic tells me it goes in the C# project, but it complains that neither Context nor Installer class exist. When I add this class to the Setup Project, it doesn't complain, but it doesn't work after that. Here's 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'm already passing
lang
as CustomActionData using /lang=[LANG] (where LANG is the radio value)

Answer

First, you should add the RunInstallerAttribute to you class.

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

Next, put the installer in a separate project (class library), e.g. MyCustomInstaller.

Finally, add the primary output of this project to a custom action in the custom actions editor of the setup project.

enter image description here

It's up to you in which custom action you want to use.

Comments