如果在Wix安装程序包中声明

时间:2016-04-29 14:00:20

标签: wix installer

我在bundle.wxs

中有一个这样的变量
<Variable Name="IsRegistryKeyExist"  />

注册表是否搜索以查找密钥是否存在。

<util:RegistrySearch
            Id="REGSEARCH"
            Root="HKLM"
            Key="SOFTWARE\MyApp\Test"
            Result="exists" 
            Variable="IsRegistryKeyExist"/>

以下if语句

<?if IsRegistryKeyExist = 0 ?>
<Variable Name="EneterdIfCase" Value="IfExecuted" />
<?else ?>
<Variable Name="EneterdIfCase" Value="ElseExecuted" />
<?endif ?>

在自定义操作中打印此变量时,无论“IsRegistryKeyExist”的值如何,它都会执行“Else”部分,基本上似乎if条件检查不正确。

以下是我到目前为止所做的试验。

<?if $(var.IsRegistryKeyExist) = 0 ?>
<?if <![CDATA[IsRegistryKeyExist = 0]]?>
<?if [IsRegistryKeyExist] = 0 ?>
<?if IsRegistryKeyExist = "0" ?>

1 个答案:

答案 0 :(得分:3)

&lt;?if xxxxx?&gt; stuff是编译时的预处理器,就像添加

一样
#ifdef DEBUG
    Log(LogLeve.Debug, "Here's a message that only happens in debug builds when DEBUG is defined.");
#endif

仅在产品的调试版本中打印调试消息。

你总是得到else的原因是因为预处理器在编译时查看你的“IsRegistryKeyExist”变量的值而你没有在你的变量声明中为它赋值,所以它, I想想,设置为空/ null /“”。 &lt;?if“”= 0?&gt;总是假的,所以它只将else case放入文件中供编译器编译并完全省略“if”部分中的代码。如果在IsRegistryKeyExist变量的定义中设置Value =“0”,它将始终包含预处理器的if部分if-else。

Here's a resource to the wix pre-processor.

相关问题