【问题标题】:Build WiX 3.6 project targeting x64?构建针对 x64 的 WiX 3.6 项目?
【发布时间】:2025-12-11 12:05:01
【问题描述】:

我的解决方案是使用平台设置“任何 CPU”构建的。对于我的WiX 3.6 安装程序项目设置,似乎无法将目标平台设置为“x64”;只有“x86”可用。可以针对 x64 构建 WiX 项目吗?

【问题讨论】:

    标签: wix


    【解决方案1】:

    Windows 安装程序无法针对任何 CPU 构建,我通常构建两次,托管代码设置为任何 CPU,而安装程序具有 x86 和 x64 两种配置。

    您可能会发现需要创建配置,这可以通过右键单击解决方案并选择配置管理器然后选择平台下的下拉菜单来完成。完成后,您应该能够在 wixproj 中看到以下定义:

      <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
        <OutputPath>bin\$(Configuration)\</OutputPath>
        <IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
        <DefineConstants>Debug</DefineConstants>
      </PropertyGroup>
      <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
        <OutputPath>bin\$(Configuration)\</OutputPath>
        <IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
      </PropertyGroup>
      <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
        <DefineConstants>Debug</DefineConstants>
        <OutputPath>bin\$(Platform)\$(Configuration)\</OutputPath>
        <IntermediateOutputPath>obj\$(Platform)\$(Configuration)\</IntermediateOutputPath>
      </PropertyGroup>
      <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
        <OutputPath>bin\$(Platform)\$(Configuration)\</OutputPath>
        <IntermediateOutputPath>obj\$(Platform)\$(Configuration)\</IntermediateOutputPath>
      </PropertyGroup>
    

    为了让安装程序同时使用 x86 和 x64 定义变量来检测和设置安装架构。

    <?if $(var.Platform) = x64 ?>
    <?define bitness = "(64 bit)" ?>
    <?define Win64 = "yes" ?>
    <?define PlatformProgramFilesFolder = "ProgramFiles64Folder" ?>
    <?else ?>
    <?define bitness = "(32 bit)" ?>
    <?define Win64 = "no" ?>
    <?define PlatformProgramFilesFolder = "ProgramFilesFolder" ?>
    <?endif ?>
    

    我将bitness 变量附加到名称作为视觉线索:

    <Product Name="My Install $(var.bitness)"
    

    酌情参考Program Files文件夹:

      <Fragment>
        <Directory Id="TARGETDIR" Name="SourceDir">
          <Directory Id="$(var.PlatformProgramFilesFolder)">
    

    组件的 Win64 标志设置得当:

    <Component Win64="$(var.Win64)"
    

    【讨论】:

    • 嗨@David Martin,谢谢,这是否意味着我需要为 x86 和 x64 构建两个单独的 MSI?
    • @sean717 是的,尽管您可以将它们都放入引导的 exe 中。但这是一个不同的问题:-)
    • @DavidMartin 我正在尝试应用您的解决方案,但我不确定我应该将这段代码放在哪里定义变量以检测和设置安装架构。 ¿ 我应该把它放在什么文件中?
    • @daniegarcia254 这些是预处理器变量,因此可以放置在您的任何 wix 文件中,请参阅此处了解更多信息wixtoolset.org/documentation/manual/v3/overview/…
    • 这对我有帮助——无论我从 GUI 中尝试什么,我都无法让 Wix 安装程序项目构建 x64 版本。我在记事本中打开项目文件,看到有几个重复的条目。删除 x64 和 x86 的重复条目后,我重新打开项目并能够构建 64 位安装程序
    最近更新 更多