2011-09-23 74 views
0

我试图遵循代码at this link才能在我的安装程序类,以确定是否设置是跑了作为沉默。但是我必须做错事,因为Context.Parameters [“UILevel”]似乎不包含任何值。如何正确检索安装程序类设置UILevel

在我的安装项目,我添加上安装自定义操作,在这里我通过/ UILevel =“[UILevel]”到CustomActionData场。然后我挂这个自定义操作来安装程序的DLL项目的主输出,其中包含下面的安装程序类:

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); 
    } 
    } 
} 

我想,如果我上添加自定义操作安装,我应该找回Context.Parameters [” UILevel“]在安装覆盖。但是Context.Parameters [“UILevel”]永远不会被填充。我也尝试在类的构造函数中检索它,但它会抛出nullref,并且在提交事件中,但仍然没有任何结果。

我该如何正确检索这个值?

回答

0

我解决了它,它正确地检索有关AfterInstall事件处理UILevel值。

private void SecureUpdaterInstaller_AfterInstall(object sender, InstallEventArgs e) 
    { 
     uiLevelString = this.Context.Parameters["UILevel"]; 
     System.Diagnostics.Process.Start("http://www.google.ro?q=afterInstall_" + uiLevelString); 
    } 

它是有道理的 - 它从安装自定义操作中填充值,并且它在AfterInstall上检索它。

相关问题