【问题标题】:WiX: Prevent 32-bit installer from running on 64-bit WindowsWiX:阻止 32 位安装程序在 64 位 Windows 上运行
【发布时间】:2010-03-16 22:14:37
【问题描述】:

由于用户混淆,我们的应用需要单独的安装程序用于 32 位和 64 位版本的 Windows。虽然 32 位安装程序在 win64 上运行良好,但它可能会造成支持问题,我们希望防止这种情况发生。

我想阻止 32 位 MSI 安装程序在 64 位 Windows 机器上运行。为此,我有以下条件:

<Condition Message="You are attempting to run the 32-bit installer on a 64-bit version of Windows.">
  <![CDATA[Msix64 AND (NOT Win64)]]>
</Condition>

Win64 定义如下:

<?if $(var.Platform) = "x64"?>
<?define PlatformString = "64-bit"?>
<?define Win64 ?>
<?else?>
<?define PlatformString = "32-bit"?>
<?endif?>

问题是,我无法让这张支票正常工作。要么一直触发,要么不触发。目标是对照编译时 Win64 变量检查运行时 msix64 变量的存在,如果这些变量不对齐,则抛出错误,但逻辑无法按我的预期工作。有没有人提出更好的解决方案?

【问题讨论】:

    标签: wix installation windows-installer wix3 platform


    【解决方案1】:

    仅在 32 位包中包含 Condition 元素(即,使用 ?if? 预处理器语句)。条件将是“NOT Msix64”:启动条件是必须为真的事情,因此如果设置了 Msix64,启动条件将失败,这意味着它是 x64 操作系统和 32 位包,正确的做法是块。

    【讨论】:

    【解决方案2】:

    我们使用以下...

    <?if $(var.ProcessorArchitecture)=x86 ?>
    <Condition Message="!(loc.LaunchCondition_Error64)">
        <![CDATA[Installed OR Not VersionNT64]]>
    </Condition>
    <?endif?>
    

    【讨论】:

    【解决方案3】:

    条件元素适用于安装过程中存在的 Windows 安装程序属性。

    但是,您将 Win64 定义为 wix 变量,而不是 Windows 安装程序属性。 Wix 变量仅在创建设置时存在。您必须在使用它们的地方将它们引用为 $(var.MyWixVariable),然后 wix 预处理器将用它们定义的值替换它们。

    我会试试这个:

    <?if $(var.Platform) = "x64"?>
    <?define PlatformString = "64-bit"?>
    <Property Id="Win64" Value="1" />
    <?else?>
    <?define PlatformString = "32-bit"?>
    <?endif?>
    

    如果 $(var.Platform) 在创建设置时具有正确的值,那么这将导致在 windows 安装程序数据库(即 MSI 文件)中记录一个“Win64”属性,并且该属性将在安装期间可用以供使用在条件元素中。

    【讨论】:

    • 这在 Wix 3.6 上运行时会引发错误,表明嵌套的 Property 元素不能使用 > 语法放置。
    • @JonSamwell:这些处理指令 (&lt;?...?&gt;) 是为 candle.exe 中的预处理器设计的。如果您正确使用 wix,Light.exe 应该永远不会看到它们。
    【解决方案4】:

    添加这个条件

    <Condition Message="This is designed for 32bit OS">%PROCESSOR_ARCHITECTURE ~= "x86" AND %PROCESSOR_ARCHITEW6432 &lt;&gt; "amd64"></Condition>
    

    您可以创建一个具有 32 位组件和 64 位组件的安装程序,并将这两个条件放在各自的组件中

    <Component Id="bit32Component" Guid="..." Feature="ProductFeature">
        <Condition>%PROCESSOR_ARCHITECTURE~="x86" AND %PROCESSOR_ARCHITEW6432&lt;&gt;"amd64"></Condition>
    </Component>
    <Component Id="bit64Component" Guid="..." Feature="ProductFeature">
        <Condition>%PROCESSOR_ARCHITECTURE~="amd64" OR %PROCESSOR_ARCHITEW6432~="amd64"></Condition>
    </Component>
    

    这是我使用的参考

    http://blogs.msdn.com/david.wang/archive/2006/03/26/HOWTO-Detect-Process-Bitness.aspx

    【讨论】:

      猜你喜欢
      • 2011-07-06
      • 1970-01-01
      • 2011-11-20
      • 1970-01-01
      • 2011-05-03
      • 1970-01-01
      • 1970-01-01
      • 2011-05-13
      • 1970-01-01
      相关资源
      最近更新 更多