如何在Burn(Wix)中比较DetectCondition中的版本变量 [英] how to compare version variables in DetectCondition in burn (wix)

查看:89
本文介绍了如何在Burn(Wix)中比较DetectCondition中的版本变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的Fragment

<Fragment>
    <Variable Name="Hasp_BundleVersion" Value="7.54.8889.1" />
    <Variable Name="Hasp_IsInstalled" />
    <Variable Name="Hasp_InstalledVersion" />

    <util:RegistrySearch Id="Hasp_IsInstalled"
                         Variable="Hasp_IsInstalled"
                         Root="HKLM"
                         Key="SOFTWARE\Aladdin Knowledge Systems\HASP\Driver\Installer"
                         Value="Version"
                         Result="exists" />

    <util:RegistrySearch Condition="Hasp_IsInstalled"
                         After="Hasp_IsInstalled"
                         Variable="Hasp_InstalledVersion"
                         Root="HKLM"
                         Key="SOFTWARE\Aladdin Knowledge Systems\HASP\Driver\Installer"
                         Value="Version"
                         Result="value" />

    <PackageGroup Id="Hasp">
        <ExePackage Id="Hasp"
                    DisplayName="Hasp"
                    SourceFile="setups\HASPUserSetup.exe"
                    Compressed="yes"
                    DetectCondition="Hasp_IsInstalled AND Hasp_InstalledVersion &gt;= Hasp_BundleVersion"
                    InstallCommand="/s /v/qn"
                    PerMachine="yes"
                    Permanent="yes" />
    </PackageGroup>
</Fragment>

这是行不通的,因为似乎它正在将两个值作为字符串进行比较.这是日志:

This doesn't work, because it seems like it is comparing the two values as strings. Here's the log:

[0A74:0A4C][2017-03-29T16:29:02]i000: Initializing string variable 'Hasp_BundleVersion' to value '7.54.8889.1'
[0A74:0A4C][2017-03-29T16:29:02]i000: Setting numeric variable 'Hasp_IsInstalled' to value 1
[0A74:0A4C][2017-03-29T16:29:02]i000: Setting string variable 'Hasp_InstalledVersion' to value '7.54.66980.1'
[0A74:0A4C][2017-03-29T16:29:02]i052: Condition 'Hasp_IsInstalled AND Hasp_InstalledVersion >= Hasp_BundleVersion' evaluates to false.

如果我更改为Version类型,则也不起作用:

If I change to type Version, it doesn't work either:

<Fragment>
    <Variable Name="Hasp_BundleVersion" Type="version" Value="7.54.8889.1" />
    <Variable Name="Hasp_IsInstalled" />
    <Variable Name="Hasp_InstalledVersion" Type="version" Value="0.0.0.0" />

    <util:RegistrySearch Id="Hasp_IsInstalled"
                         Variable="Hasp_IsInstalled"
                         Root="HKLM"
                         Key="SOFTWARE\Aladdin Knowledge Systems\HASP\Driver\Installer"
                         Value="Version"
                         Result="exists" />

    <util:RegistrySearch Condition="Hasp_IsInstalled"
                         After="Hasp_IsInstalled"
                         Variable="Hasp_InstalledVersion"
                         Root="HKLM"
                         Key="SOFTWARE\Aladdin Knowledge Systems\HASP\Driver\Installer"
                         Value="Version"
                         Result="value" />

    <PackageGroup Id="Hasp">
        <ExePackage Id="Hasp"
                    DisplayName="Hasp"
                    SourceFile="setups\HASPUserSetup.exe"
                    Compressed="yes"
                    DetectCondition="Hasp_IsInstalled AND Hasp_InstalledVersion &gt;= Hasp_BundleVersion"
                    InstallCommand="/s /v/qn"
                    PerMachine="yes"
                    Permanent="yes" />
    </PackageGroup>
</Fragment>

日志:

[1B40:0CEC][2017-03-29T16:42:23]i000: Initializing version variable 'Hasp_BundleVersion' to value '7.54.8889.1'
[1B40:0CEC][2017-03-29T16:42:23]i000: Initializing version variable 'Hasp_InstalledVersion' to value '0.0.0.0'
[1B40:0CEC][2017-03-29T16:42:23]i000: Setting numeric variable 'Hasp_IsInstalled' to value 1
[1B40:0CEC][2017-03-29T16:42:23]i000: Setting string variable 'Hasp_InstalledVersion' to value '7.54.66980.1'
[1B40:0CEC][2017-03-29T16:42:23]i052: Condition 'Hasp_IsInstalled AND Hasp_InstalledVersion >= Hasp_BundleVersion' evaluates to false.

我正在使用Variables,因为稍后需要在自定义引导程序中访问值.

I'm using Variables, because I need to access the values later in my custom bootstrapper.

我在做什么错了?

推荐答案

水平线下面是我的原始回答,我认为这是错误的. 您可以像roli09那样定义版本变量,即:

Below the Horizontal line is my original response which I think is wrong. You define a version variable as roli09 did ie:

<Variable Name="Hasp_BundleVersion" Type="version" Value="7.54.8889.1" />

,并且您不需要'v'.如果您要执行以下条件,则确实需要v:

and you don't need the 'v'. You do need the v if you are doing a condition like this:

Condition="InstalledVersion &gt;= v7.0.2.1"

以便编译器将第二个操作数作为版本处理.

So that the compiler processes the second operand as a version.

我认为这里发生的是在第一个代码段中,我们将这两个版本都视为字符串变量.作为字符串,将它们逐个字符地进行比较,"6" < '8',所以我们得到了错误的结果.

What I think happened here is in the first code snippet, we have both versions being treated as string variables. And as strings they are compared character by character and '6' < '8' so we get false.

在第二个代码片段中,我相信我们最终得到了两个Hasp_InstalledVersion变量.捆绑软件中定义的一个是版本"变量,而RegistySearch定义的是一个字符串变量.我猜在这种情况下它会比较两个版本变量,所以

In the second code snippet I believe we end up with two Hasp_InstalledVersion variables. The one defined in the bundle which is a "version" variable and the one defined by the RegistySearch which is a string variable. I'm am guessing that in the condition it compares both version variables so this

Hasp_InstalledVersion &gt;= Hasp_BundleVersion

成为

0.0.0.0 >= 7.54.8889.1

这是错误的.

要解决此问题,请定义

<Variable Name="Hasp_BundleVersion" Type="version" Value="7.54.8889.1" />

但不定义

<Variable Name="Hasp_InstalledVersion" Type="version" Value="0.0.0.0" />

现在,它应该将注册表搜索中的字符串变量与proj文件中定义的版本变量进行比较.在burning的condition.cpp中,如果您有字符串变量OPERATION版本变量",它将尝试将字符串变量转换为版本变量并进行版本比较.

Now it should compare the string variable from the registry search to the version variable defined in in the proj file. In condition.cpp of burn, if you have a "string variable OPERATION version variable", it tries to convert the string variable to a version variable and do version comparison.


蜡烧伤状况评估有点混乱.

Wix burn condition evaluation is a bit confusing.

我前一阵子研究了这个确切的问题.我认为问题在于您错误地定义了版本值.

I dug into it a while ago to figure out this exact issue. I believe the issue is that you're defining the version value incorrectly.

此外,我不确定您可以使用

Also, I'm not sure you can use

<Variable Name="Hasp_InstalledVersion" Type="version" Value="0.0.0.0" />

因为RegistrySearches设置的所有变量都是字符串变量.我不确定现在是否定义了两个Hasp_InstalledVersion变量,因为一个是版本"变量,另一个是字符串"版本.不想深入研究wix源,就像在您的第一个代码段中一样,我坚持将其保留为非类型变量.

since all variables set by RegistrySearches are string variables. I'm not sure if you end up having two Hasp_InstalledVersion variables defined now since one is a "version" variable and the other is a "string" version. Without wanting to delve into the wix source I would just stick to leaving it as a non-typed variable like in your first code snippet.

现在,在固定条件时,根据条件变量的格式,在条件评估中会将字符串变量提升为其他类型的变量.即:string op string将进行字符串比较,string op版本将进行版本比较.

Now, onto fixing your condition, in the conditional evaluation there is promotion of string variables to other types of variables depending on the format of said variables. ie: string op string will do string comparison, string op version will do version comparison.

格式化变量以表明它是版本的方式是在其前面放置一个"v".因此,我相信将Hasp_BundleVersion更新为

The way you format a variable to indicate it is a version is to just put a 'v' in front of it. So, I believe your issue will be solved if you update your Hasp_BundleVersion to be

<Variable Name="Hasp_BundleVersion" Value="v7.54.8889.1" />

或者更好的是,您可以在包含文件或属性文件中定义版本(对于msbuild,然后包含在DefineConstants中),然后可以将代码更新为

Or better yet, you define the version somewhere in a include file or a property file (for msbuild, then included in DefineConstants) and you can update your code to

<Variable Name="Hasp_BundleVersion" Value="v$(var.HaspBundleVersion)" />

但是我认为走这条路只是偏好问题.

But going this far is just a matter of preference I think.

这篇关于如何在Burn(Wix)中比较DetectCondition中的版本变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆