问题描述
我试图根据应该在自定义操作中设置的值从两个功能中安装一个。
首先,我设置属性的值:
I am trying to install one from two features based on the value that should be set inside of the custom action.
Firstly, I set the value of a property:
UINT __stdcall ConfigurationCheckAction(MSIHANDLE hInstall)
{
HRESULT hr = S_OK;
UINT er = ERROR_INSTALL_FAILURE;
hr = WcaInitialize(hInstall, "ConfigurationCheckAction");
if (condition) {
MsiSetProperty( hInstall, TEXT("STREAM"), TEXT("RED") );
}
else {
MsiSetProperty( hInstall, TEXT("STREAM"), TEXT("BLUE") );
}
return WcaFinalize(er);
}
其次,我每两个特征取两个条件:
Secondly, I make two conditions per two features:
<Feature Id='Complete' Level='1'>
<Feature Id="Red" ConfigurableDirectory="TARGETDIR" Title="F1" Level="0">
<Condition Level="1">STREAM</Condition>
</Feature>
<Feature Id="Blue" ConfigurableDirectory="TARGETDIR" Title="F2" Level="0">
<Condition Level="1">NOT STREAM</Condition>
</Feature>
</Feature>
请注意,我之前并未在wxs文件中定义属性,因为我想设置
Note that I don't define property inside of the wxs file previously, as I would like to set it from the custom action.
在InstallInitialize和Execute立即执行之前调用我的自定义动作。
My custom action is called before InstallInitialize and Execute is immediate.
从安装日志我已经确认该属性已设置。
但是,我的条件安装无法正常工作,因为条件中的内容始终被评估为false。
From the installation log I have confirmation that the property is set.However, my conditional installation does not work, as it seems like what is in the condition is always evaluated as false.
我尝试评估条件:
STREAM,STREAM = RED,STREAM = RED,< ![CDATA [STREAM = RED]]>
I tried evaluating conditions:STREAM, STREAM=RED, STREAM="RED", < ![CDATA[STREAM=RED]]>
我的想法已经用完了,希望得到帮助。
I am running out of ideas what to do and would appreciate help.
推荐答案
感谢您的答复。最后,您的建议的组合对我有所帮助。
Thank you for your replies. In the end, a combination of your suggestions helped me.
我想说明什么是有效的,什么是无效的:
I want to state what did and what did not work:
- 没有必要使用默认值向WiX添加属性(以及添加此属性Secure ='yes'的属性)
- 调用自定义在CostInitialize之前采取行动并不能单独解决问题,但我认为这是解决问题的因素之一。
- 有条件的税率已通过以下方式纠正:
a )将条件放在CDATA内,并按建议在属性值中加上引号:< Condition><![CDATA [STREAM = RED]]>< / Condition&
b)反转条件级别,因此功能部件具有条件级别1,条件部件具有级别0。这意味着始终安装该功能部件,除非条件表达式为false。
- Adding property to WiX with a default value was not necessary (as well with adding property of this property Secure='yes')
- Calling custom action before CostInitialize did not solve the problem on its own, but I believe it was one of the factors that resolved an issue.
- Conditional sintax was corrected by:
a) Putting condition inside of CDATA and adding quotes to the value of property as suggested:<Condition><![CDATA[STREAM="RED"]]></Condition>
b) Reversing condition levels so feature has condition level 1 and condition has level 0. This means that feature is always installed, unless the condition expression is false.
这篇关于如何根据自定义操作中设置的属性安装功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!