为啥 FileSearch 元素的 MinVersion 属性在我的 WiX 安装程序中不起作用?

Posted

技术标签:

【中文标题】为啥 FileSearch 元素的 MinVersion 属性在我的 WiX 安装程序中不起作用?【英文标题】:Why doesn't the FileSearch element's MinVersion attribute work in my WiX installer?为什么 FileSearch 元素的 MinVersion 属性在我的 WiX 安装程序中不起作用? 【发布时间】:2015-08-17 03:30:39 【问题描述】:

我正在使用WiX Toolset 编写Windows 安装程序包。我的应用程序与 Windows 窗体 WebBrowser 控件(基本上是 Internet Explorer)集成在一起,我需要确保安装程序中的 Internet Explorer 版本最低。我没有在 WiX 中找到一种简单的内置方法来检查 Internet Explorer 版本(与 .NET Framework 一样),所以我正在关注 WiX 教程的 instructions for checking a file's version number during installation 以及 Microsoft 的 documentation of Internet Explorer version numbers(在标题下) , 如何确定 Windows 版 Internet Explorer 的版本,第三个要点)。

这是我的 Product.wxs 文件中的相关代码,其中包含解释性 cmets:

<Property Id="IE10ORHIGHER">
  <DirectorySearch Id="ProgFolder" Path="[ProgramFilesFolder]\Internet Explorer">
    <!-- I tried the following line to ensure that my DirectorySearch Path 
         and FileSearch Name attributes were functioning correctly.
         This line--without MinVersion set--results in the IE10ORHIGHER
         property being defined during installation, but it is useless
         because it merely detects that iexplore.exe exists rather than
         ensuring a minimum version.  -->
    <!-- <FileSearch Name="iexplore.exe" /> -->

    <!-- I need Internet Explorer 10 at minimum. -->
    <!-- IE10 RTM for Windows 8 version number: 10.0.9200.16384 -->
    <!-- IE10 RTM for Windows 7 version number: 10.0.9200.16521 -->
    <!-- Use IE10 RTM for Windows 8 version string. Minimum in FileSearch
         must be desired revision minus 1. See
         https://msdn.microsoft.com/library/aa371853.aspx -->
    <FileSearch Name="iexplore.exe" MinVersion="10.0.9200.16383" />
  </DirectorySearch>
</Property>

<!-- Requires Internet Explorer 10 or higher. -->
<Condition Message="This application requires Internet Explorer 10 or higher. Please upgrade Internet Explorer, and then run this installer again.">
  <![CDATA[Installed OR IE10ORHIGHER]]>
</Condition>

我正在运行 Windows 8.1,并且我已验证我系统上的 iexplore.exe 版本是 11.0.9600.17840。但是,当我使用完整日志记录 (/l*vx) 编译和运行安装程序时,会显示我的条件消息,并且未安装该软件。这是我的 MsiExec 日志文件的摘录,显示了对文件的搜索,并插入了星号以指出重要的行:

行动 22:10:12:AppSearch。搜索已安装的应用程序
行动开始 22:10:12:AppSearch。
★AppSearch:属性:IE10ORHIGHER,签名:ProgFolder
AppSearch:属性:NETFRAMEWORK45,签名:NetFramework45
MSI (c) (BC:54) [22:10:12:849]:属性更改:添加 NETFRAMEWORK45 属性。它的值为“#379893”。
行动于 22:10:12 结束:AppSearch。返回值 1。
MSI (c) (BC:54) [22:10:12:849]:执行操作:LaunchConditions
MSI (c) (BC:54) [22:10:12:849]: 注意: 1: 2205 2: 3: ActionText
行动 22:10:12:启动条件。评估发射条件
行动开始 22:10:12:LaunchConditions。
MSI (c) (BC:48) [22:10:12:856]:字体已创建。字符集:Req=0,Ret=0,字体:Req=MS Shell Dlg,Ret=MS Shell Dlg
★此应用程序需要 Internet Explorer 10 或更高版本。请升级 Internet Explorer,然后再次运行此安装程序。
MSI (c) (BC:54) [22:10:14:276]: 注意: 1: 2205 2: 3: 错误
MSI (c) (BC:54) [22:10:14:276]: 注意: 1: 2228 2: 3: Error 4: SELECT `Message` FROM `Error` WHERE `Error` = 1709
★MSI (c) (BC:54) [22:10:14:276]: Product: MyProductName -- 此应用程序需要 Internet Explorer 10 或更高版本。你已经安装了。请升级 Internet Explorer,然后再次运行此安装程序。

行动于 22:10:14 结束:LaunchConditions。返回值 3。
行动于 22:10:14 结束:安装。返回值 3。
属性(C):UpgradeCode = MY-GUID-REMOVED
属性(C):NETFRAMEWORK45 = #379893

相比之下,这是我重新编译时安装的日志文件,省略了 FileSearch 元素的 MinVersion 属性。在这种情况下,iexplore.exe文件肯定找到了,属性设置好了,程序安装正常(当然,这是省略了我需要完成的版本检查!)

动作开始时间 21:40:48:AppSearch。
AppSearch:属性:IE10ORHIGHER,签名:ProgFolder
★MSI (c) (98:14) [21:40:48:761]:属性更改:添加 IE10ORHIGHER 属性。它的值是'C:\Program Files\Internet Explorer\iexplore.exe'。
AppSearch:属性:NETFRAMEWORK45,签名:NetFramework45
MSI (c) (98:14) [21:40:48:762]:属性更改:添加 NETFRAMEWORK45 属性。它的值为“#379893”。
行动于 21:40:48 结束:AppSearch。返回值 1。
MSI (c) (98:14) [21:40:48:762]:执行操作:LaunchConditions
MSI (c) (98:14) [21:40:48:762]: 注意: 1: 2205 2: 3: ActionText
行动 21:40:48:启动条件。评估发射条件
行动开始时间 21:40:48:LaunchConditions。
行动于 21:40:48 结束:LaunchConditions。返回值 1。

★★★关于安装进度的多行此处略过★★★

属性(C):UpgradeCode = MY-GUID-REMOVED
★属性(C):IE10ORHIGHER = C:\Program Files\Internet Explorer\iexplore.exe
属性(C):NETFRAMEWORK45 = #379893

为什么我的 FileSearch 无法识别 iexplore.exe 的版本 11.0.9600.17840 大于 MinVersion 属性的值 10.0.9200.16383?


更新问题原因和修订问题 - 2015-08-25

为了响应Christopher Painter 和Kiran Hegde 的回答,我开始制作我的安装程序项目的最小版本,它仍然会显示错误。这样做,我发现了问题:我的安装程序是dual-purpose package;默认情况下,它按用户运行,因此指定Path="[ProgramFilesFolder]\Internet Explorer" 的 DirectorySearch 元素在%LOCALAPPDATA%\Programs 下搜索,而不是在%ProgramFiles% 下搜索。我通过在命令提示符下尝试以下解决方法/测试来验证是这种情况,这两种方法都允许安装程序成功完成:

解决方法/测试 1 - 将 IE 复制到安装程序正在查找的位置

robocopy "%ProgramFiles%\Internet Explorer" "%LOCALAPPDATA%\Programs\Internet Explorer" iexplore.exe
msiexec /package MyProductName.msi
rd /s /q "%LOCALAPPDATA%\Programs\Internet Explorer"

解决方法/测试 2 - 指定每台机器的安装

msiexec /package MyProductName.msi ALLUSERS=1

找到问题的原因很好,但我仍然有问题。我的安装程序需要根据用户的选择在每个用户或每个计算机的上下文中运行。由于 MSI 的 ProgramFilesFolder 变量特定于安装上下文,在每个用户上下文中运行时,我如何测试 %ProgramFiles% 下的 IE 版本?

【问题讨论】:

【参考方案1】:

您能否在测试项目中尝试您正在尝试做的事情,看看它是否按预期工作?因为我在一个测试项目中尝试了你的一段代码,它按预期工作。 我使用 windows 7 64 位环境,我系统上的 iexplore.exe 版本是 11.0.9600.17937。如果我在 MinVersion 字段中使用 11.0.9600.17937,我会看到消息(即所需的最低未找到 11.0.9600.17938 的版本。如果我在 MinVersion 字段中使用 11.0.9600.17936,我看不到该消息(即所需的最低版本 11.0.9600.17937 已找到)无论是 Windows 7 还是 Windows 8 环境都无关紧要,因为此行为由 Windows 安装程序框架决定。 顺便说一句,当您说省略版本检查时,您是什么意思? 如果未找到所需的 Internet Explorer 最低版本,您只会看到启动条件触发。只要日志表明:LaunchConditions。评估启动条件,它足以安全地假设正在执行版本检查。

这是我的测试项目:

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Product Id="*" Name="FileSearch" Language="1033" Version="1.0.0.0" Manufacturer="Test" UpgradeCode="8790de3a-ca66-4577-b3cd-5a9df0ab15b2">
        <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine"  />

        <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
        <MediaTemplate EmbedCab="yes" />

        <Feature Id="ProductFeature" Title="FileSearch" Level="1">
            <ComponentGroupRef Id="ProductComponents" />
        </Feature>

    <Property Id="IE10ORHIGHER">
  <DirectorySearch Id="ProgFolder" Path="[ProgramFilesFolder]\Internet Explorer">
    <!-- I tried the following line to ensure that my DirectorySearch Path 
         and FileSearch Name attributes were functioning correctly.
         This line without MinVersion set results in the IE10ORHIGHER
         property being defined during installation, but it is useless
         because it merely detects that iexplore.exe exists rather than
         ensuring a minimum version.  -->
    <!-- <FileSearch Name="iexplore.exe" /> -->

    <!-- I need Internet Explorer 10 at minimum. -->
    <!-- IE10 RTM for Windows 8 version number: 10.0.9200.16384 -->
    <!-- IE10 RTM for Windows 7 version number: 10.0.9200.16521 -->
    <!-- Use IE10 RTM for Windows 8 version string. Minimum in FileSearch
         must be desired revision minus 1. See
         https://msdn.microsoft.com/library/aa371853.aspx -->
    <FileSearch Name="iexplore.exe" MinVersion="11.0.9600.17936" />
  </DirectorySearch>
</Property>

<!-- Requires Internet Explorer 10 or higher. -->
<Condition Message="This application requires Internet Explorer 10 or higher. Please upgrade Internet Explorer, and then run this installer again.">
  <![CDATA[Installed OR IE10ORHIGHER]]>
</Condition>
    </Product>

    <Fragment>
        <Directory Id="TARGETDIR" Name="SourceDir">
            <Directory Id="ProgramFilesFolder">
                <Directory Id="INSTALLFOLDER" Name="FileSearch" />
            </Directory>
        </Directory>
    </Fragment>

    <Fragment>
        <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">

             <Component Id="ProductComponent" Guid="6CD6FBF0-8FE4-4882-80E1-DC16B9CED222"> 
                <!-- TODO: Insert files, registry keys, and other resources here. -->
         <File Id="ProductFile" KeyPath="yes" Source="E:\Learning\Test Projects\Files\abc.dll" Name="abc.dll" />
            </Component> 
        </ComponentGroup>
    </Fragment>
</Wix>

【讨论】:

我将您的代码复制到一个新项目中,将“C:\Windows\System32\notepad.exe”替换为“E:\Learning\Test Projects\Files\abc.dll”。在我的机器上,Internet Explorer 的版本是 11.0.9600.17905。我使用以下 MinVersion 值编译并运行此安装程序 3 次:“11.0.9600.17905”、“11.0.9600.17904”和“11.0.9600.17900”。据我了解,第一个值应该导致出现消息(中止安装),而后两个值应该在没有显示消息的情况下安装。但是,在所有三种情况下,都会显示消息,并且安装被中止。 为了回答你的问题,当我写“当我重新编译时省略了 FileSearch 元素的 MinVersion 属性”时,我解释说第二个日志文件摘录是我用“" 而不是 "" 用于测试目的。 很奇怪。为我工作,没有任何问题,但不是你。您使用的是什么版本的 Wix? 感谢您的回答。我开始将我的安装程序逐个复制到一个新项目中,以找出问题所在,在这样做的过程中,我突然意识到了原因。不过,我仍然不知道如何获得我想要的确切行为。我已经用完整的描述更新了这个问题。【参考方案2】:

我无法重现您的问题,它对我有用。您是在合并模块中执行此操作吗?如果是这样,ProgramFilesFolder 将被模块化,并且不会解析到您认为它会解析的目录,除非您将其对齐。

通常当涉及到签名表(文件搜索)时,要知道的是它会考虑语言,如果您不指定它,则不包括边界。见:

Signature Table

注意语言列中指定的语言用于 比较并没有办法忽略语言。如果你想要一个文件 为了满足 MinVersion 字段要求,无论语言如何,您 必须在 MinVersion 字段中输入一个比 实际价值。例如,如果过滤器的最低版本是 2.0.2600.1183,使用2.0.2600.1182查找不匹配语言信息的文件。

【讨论】:

不,这不在合并模块内,据我所知,我遵循了您引用的指导(甚至在我的源代码中包含了指向同一 MSDN 页面的链接)。我想要的最低版本是 10.0.9200.16384,我正在测试 10.0.9200.16383。 我需要你提供一个完整的最小样本来看看你做错了什么。多年来我一直在进行文件搜索,它确实有效。 感谢您的回答和评论。我开始按照您的建议(最小样本)工作,并发现了问题,但我仍在寻找一种方法来实现我的初衷。我已经用完整的描述更新了这个问题。

以上是关于为啥 FileSearch 元素的 MinVersion 属性在我的 WiX 安装程序中不起作用?的主要内容,如果未能解决你的问题,请参考以下文章

测试:FileSearch文件搜索项目

eclipse中ctrl+h默认打开是JavaSearch,怎么设置成默认打开是FileSearch

为啥切片追加元素不更新引用的元素?

为啥临时变量需要更改数组元素以及为啥需要在最后取消设置?

为啥删除元素比添加元素需要更多时间?

为啥列表元素不交换?