how to correctly retrieve setup UILevel in installer class
I am trying to follow the code at this link in order to determine in my installer class if the setup is ran as silent. But I must开发者_StackOverflow社区 be doing something wrong, because the Context.Parameters["UILevel"] seems to contain no value.
In my setup project, I added a custom action on Install, where I passed /UILevel="[UILevel]" into CustomActionData field. I then linked this custom action to the primary output of the installer dll project, which contains the installer class below:
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.Linq;
namespace CustomActionLibrary
{
[RunInstaller(true)]
public partial class MyInstaller : Installer
{
string uiLevelString = string.Empty;
public bool IsSilentInstall
{
get
{
if (!String.IsNullOrEmpty(uiLevelString))
{
int level = Convert.ToInt32(uiLevelString);
return level <= 3;
}
else
return false;
}
}
public MyInstaller()
{
InitializeComponent();
}
public override void Install(IDictionary stateSaver)
{
base.Install(stateSaver);
uiLevelString = Context.Parameters["UILevel"];
}
public override void Commit(IDictionary savedState)
{
//System.Diagnostics.Process.Start("http://www.google.ro?q=" + uiLevelString);
if (IsSilentInstall)
{
//do stuff here if it's silent install.
}
base.Commit(savedState);
}
}
}
I thought that if I add the custom action on Install, I should retrieve Context.Parameters["UILevel"] in the Install override. But Context.Parameters["UILevel"] never gets populated. I also tried retrieving it on the constructor of the class but it throws nullref, and in the commit event, but still nothing.
How could I properly retrieve this value?
I solved it, it's retrieving the UILevel value correctly on the AfterInstall event handler.
private void SecureUpdaterInstaller_AfterInstall(object sender, InstallEventArgs e)
{
uiLevelString = this.Context.Parameters["UILevel"];
System.Diagnostics.Process.Start("http://www.google.ro?q=afterInstall_" + uiLevelString);
}
It makes sense - it's populating the value from the Install custom action, and it's retrieving it on AfterInstall.
精彩评论