构建针对x64的WiX 3.6项目?

31
我的解决方案是使用“Any CPU”平台设置构建的。对于我的WiX 3.6安装程序项目设置,似乎我不能将目标平台设置为“x64”,只能选择“x86”。WiX项目可以针对x64构建吗?
1个回答

49

无法为任意CPU构建Windows安装程序,我通常要建立两次,托管代码设置为Any 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
@sean717 是的,虽然你可以将它们都放入引导程序 exe 中。但那是另一个问题 :-) - David Martin
@DavidMartin,我正在尝试运用你的解决方案,但是我不确定应该将代码片段放在哪里,其中你定义了检测和设置安装体系结构的变量。请问我应该把它放在哪个文件中? - daniegarcia254
@daniegarcia254 这些是预处理器变量,因此可以放置在您的任何wix文件中。有关更多信息,请参见此处:http://wixtoolset.org/documentation/manual/v3/overview/preprocessor.html - David Martin
3
这对我非常有帮助——我无论如何都无法在Wix安装程序项目中通过GUI构建x64版本。我用记事本打开了项目文件,发现有几个重复的条目。一旦我删除了x64和x86的重复条目,重新打开项目,我就能够构建一个64位的安装程序了。 - user1532208

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接