Platform identification in WiX 3.0
Asked Answered
O

3

14

I am facing issues when migrating the managed code from x86 to x64 platform. I have a WiX project to create an MSI which will be executed through Bootstrapper.

On an x86 platform, files get copied in “Program Files” as per the Project.wxs file. But if the same MSI is installed on an x64 platform through Bootstrapper, all the installation files get copied by default in “Program Files (x86)” and the application’s functionality failed as it could not find the necessary files in the 12-hive hierarchy of Program Files (for 64-bit it is “C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\CONFIG”).

I have tried using preprocessor variables like <?if $(var.ProcessorArchitecture)=x64 ?>, but I need to hardcode this variable in the project property to either x86 or x64. Finally I end up with two different MSIs for two different platforms which is not a desirable solution for me.

So, through WiX, is it possible to identify the platform to ensure installation at the desired location?

Oceanography answered 3/12, 2009 at 6:18 Comment(0)
B
21

I don't believe you will be able to have a single MSI that will support both platforms. You will need to create one for x86 and another x64 - the good news is that you don't need to maintain another WiX project to achieve this.

The way I've done this in the past is to have the following at the beginning of your product definition.

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">

    <?if $(var.Platform)=x64 ?>
      <?define msiProductId = "102F7DF4-19A6-4d3d-987F-FF57A2031593" ?>
      <?define win64Flag = "yes" ?>
    <?else ?>
      <?define msiProductId = "8AE46CAF-220F-4B9F-9527-D4A19A27C45B" ?>
      <?define win64Flag = "no" ?>
    <?endif ?>

    <Product Id="$(var.msiProductId)"
             Name="My Product"
             Language="1033"
             Version="1.0.0"
             Manufacturer="Acme"
             UpgradeCode="E2575E4A-A62E-4460-B96D-B722C79C8EAA">

        <Package InstallerVersion="400"
                 Compressed="yes"
                 InstallPrivileges="elevated"
                 Platform="$(var.Platform)"
        />

        <!-- Rest of product definition goes here -->

    </Product>
</Wix>

I forget where I got the advice to use a different ProductID for each platform.

I created the 'win64Flag' variable to get other WiX elements to work nicely in the cross-platform scenarios. As an example, here's how you use it to make a single RegistrySearch definition work for both platforms and should resolve the issue you are having with locating the 12-hive hierarchy.

<Property Id="WSE12DIRECTORY">
    <RegistrySearch Id="Reg_WSE12DIRECTORY"
                    Type="raw"
                    Root="HKLM"
                    Key="SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\12.0"
                    Name="Location"
                    Win64="$(var.win64Flag)"
    />
</Property>

With all this in place, then it is just a case of passing the relevant value for the 'Platform' pre-processor variable on the Candle command-line, or selecting the target platform in Visual Studio.

Benavidez answered 7/12, 2009 at 14:3 Comment(3)
In WiX 3, use of the platform attribute is discouraged. They recommend to leave it out and use the -arch switch for candle instead. wix.sourceforge.net/manual-wix3/wix_xsd_package.htmHeadless
You may need to use sys.BUILDARCH instead of var.Platform.Jecoa
Umm, as far as I understand Windows Installer supports installing both 32-bit and 64-bit components with one single MSI. It's the MSI that can only specify a single architecture, but it may embed both 32 and 64 bit and Windows Installer is capable of installing both with one installation procedure. Given how these components can belong to same or different features, there is a lot of room for different designs. Reference: learn.microsoft.com/en-us/windows/win32/msi/…Revelry
W
15

You can use the Condition statement (documentation here) which will detect which platform the installer is running on at install time. This allows you to create just one installer which will work on all platforms.

The test for 64-bit platform is VersionNT64 and conversely the test for non 64-bit platforms is NOT VersionNT64.

For example:

<Component Id="SomeComponentId" Guid="SomeGuid">
    <Condition>
        <![CDATA[NOT(VersionNT64)]]>
    </Condition>
    <File Id="SomeFile" Name="Somefile.exe" Source="$(var.UI.TargetDir)\ProjectOutput.exe" />
</Component>
Wildebeest answered 31/12, 2009 at 2:25 Comment(3)
Thanks. Now here is the other problem for WIX : Through WIX, when I’m fetching installation path for a 64-bit components by accessing its registry key, because of registry redirection it is redirected to WOW6432node where registry keys doesn’t exist. So, through WIX, is there any way to look into the 64-bit Registry View with only Single MSI creation? As far as I know, a component must be marked as Win64="yes" in order to cause registry entries to be written under the 64-bit registry hive instead of the WOW64 registry hive. Any other suggestions?Oceanography
This issue is addressed in the solution I offered in my answer.Benavidez
@PeterMortensen. Yes. Fixed.Trainor
C
3

You can use

candle -arch x86 

or

candle -arch x64 

and as result the Platform="x64" and Win64="true" attributes will be generated.

Chicago answered 23/8, 2012 at 10:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.