【发布时间】:2018-01-15 05:24:04
【问题描述】:
我正在尝试按照代码 at this link 来确定我的安装程序类中的设置是否以静默方式运行。但我一定是做错了什么,因为 Context.Parameters["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);
}
}
}
我认为如果我在 Install 上添加自定义操作,我应该在 Install 覆盖中检索 Context.Parameters["UILevel"]。但是 Context.Parameters["UILevel"] 永远不会被填充。我也尝试在类的构造函数上检索它,但它抛出 nullref,并在提交事件中,但仍然没有。
如何正确检索此值?
【问题讨论】:
标签: overriding custom-action silent-installer