Jelle Druyts .NET Consultant
Just another ignorant weirdo from Antwerp, Belgium trying to make sense out of it all
I've recently needed to create an installer with custom actions that only need to be run when the user selects certain options in the installation wizard. It's pretty easy to do once you know the pitfalls, but it took me some time to figure out so I figured I might as well post it for future reference...
One option is to create a separate assembly for each custom action that can be selected, and then setting its Condition property so that it is only executed if the user chose the corresponding option.
Condition
However, this could result in quite a lot of extra assemblies (currently three in my case, but it might become more), which I try to avoid to make it easier to deploy and use these custom actions. So I wanted one assembly containing all the installer classes that could need to be run, and then decide inside that assembly which ones to execute based on the user's choice. This is what worked for me:
CustomActionData
[RunInstaller(false)]
Install
savedState
[RunInstaller(true)]
Installers
stateSaver
if (this.Context.Parameters["OPTION1"] == "1") { this.Installers.Add(new Option1Installer()); stateSaver["OPTION1"] = "1"; }
base.Install
Commit
Rollback
if (savedState["OPTION1"] == "1") { this.Installers.Add(new Option1Installer()); }
Uninstall
This is what worked for me, if there are simpler ways of achieving the same thing, don't hesitate to make suggestions