4

我正在尝试使用 WiX 3.0 组装一个安装程序,但我不确定一件事。我想使用该FeaturesDlg对话框允许用户选择要安装的功能,但我需要能够根据之前收到的一些输入有条件地从列表中排除一些功能,最好是来自托管自定义操作。

我看到,如果我在 .wxs 文件中将Displaya 的属性设置Feature为它会执行我想要的操作,但我无法找到在运行时更改该属性的方法。hidden

任何指针都会很棒。

编辑

我尝试使用 SQL 更新会话数据库,但是虽然我实际上可以使用 删除该功能,但DELETE FROM Feature WHERE Feature = 'featureId'如果我尝试使用UPDATE Feature SET Display=0 WHERE Feature='featureId',我会收到UPDATE FAILED错误消息。如果我尝试将值设置Display为已经设置的值以外的任何值,我会收到该错误。

删除该功能几乎已经足够好了,但是如果用户返回并更改一些输入数据,我需要能够返回并重新添加该功能。

4

3 回答 3

3

The example above is the correct way to conditionally offer a feature (except that it's recommended that the condition should be in a CDATA section), however since you said you wanted to decide this in your custom action...

Given a feature like this:

<Feature Id="MyFeature" Title="My Title" Level="1" >
  <Condition Level="0"><![CDATA[NOT(INSTALLMYFEATURE~="TRUE")]]></Condition>
  <ComponentGroupRef Id="MyFeatureComponentGroup" />
</Feature>

In your managed custom action you receive a "Session" object. If you want to make the feature available for the user, set the INSTALLMYFEATURE property to "True", otherwise set it to "False".

session["INSTALLMYFEATURE"] = "True";

or

session["INSTALLMYFEATURE"] = "False";
于 2011-03-02T04:07:05.290 回答
3

我需要做同样的事情并发现这个......

创建一个属性..将由 CA 或其他设置...

  <Property Id='INSTALL_FEATURE_2'>YES</Property>

然后使用功能内的属性...

  <Feature Id='ASecondFeature' Title='Feature 2' Level='1'>
    <Condition Level='0'>INSTALL_FEATURE_2 = "NO"</Condition>
    <ComponentGroupRef Id='secondComponent'/>  
  </Feature>

注意条件doseent直接设置父是否安装为文件等,它设置了父功能的Level属性。将其设置为 0 使其隐藏...瞧!

于 2010-10-21T10:38:09.373 回答
3

好吧,我想我偶然找到了解决方案。经过一系列试验后,我遇到了来自 MSI 的一条错误消息,该消息有点描述了当前会话中功能表的一些列,并且有一个列“RuntimeLevel”在我能找到的任何文档中都没有描述。所以我尝试了这个:

session.Database.Execute("UPDATE Feature SET RuntimeLevel=0 WHERE Feature='MyFeature'");

它奏效了;该功能不再列在选择树中。然后我再次使用 RuntimeLevel=1 运行相同的查询,它再次被列出。

由于我不确定此解决方案是否有任何奇怪的含义,因此我将把这个问题留待一段时间,以防万一其他人有“更好”的解决方案。

于 2010-05-01T08:02:19.150 回答