1
votes

I'm using WiX to build an installation package for a product at my company and I want to be able to build two slightly different versions of the .msi depending on if it is meant to be used internally in the company for testing or externally for customers.

The internal version should be built with no UpgradeCode, so that we can have several versions installed at the same time for comparison. The external version should have a static UpgradeCode.

WiX does not allow me to have UpgradeCode auto generated by doing this:

<?if $(var.Configuration) = "Internal Release"?>
   <?define UpgradeCode = "*"?>
<?else?>
   <?define UpgradeCode = "[REALGUID]"?>
<?endif?>

<Product ... UpgradeCode="$(var.UpgradeCode)">

To have the UpgradeCode "auto generated" you have to completely ommit the UpgradeCode attribute.

Anyone have any suggestions on how to accomplish this?

2

2 Answers

0
votes

Probably you can't use * for Upgrade Code (i'm not sure) but you could pass it as property through msbuild which i do for ProductCode conditionaly (if we are building patches or not)

<UpgradeCode Condition="$(InternalRelease)==1">{$([System.Guid]::NewGuid().ToString().ToUpper())}</UpgradeCode>

In your msbuild.proj add that property in your Target/msbuild project/Properties. Add UpgradeCode=$(UpgradeCode) in you constants (wixproj)

Then in your main wxs add something like this:

<?if $(var.UpgradeCode)=""?>
     <?define UpgradeCode=your-static-upgradecode ?>
<?endif?>

So if the project receives the upgrade code then it will use that one otherwise will be your fixed upgrade code in defined.

And finally to generated the guid call the msbuild.proj with /p:InteralRelease=1

0
votes

Adding this answer as an alternative solution for other users with the same challenge.

Altough IlirB's answer probably would work as expected (I haven't tried it as I solved the problem with my own solution before the answer was provided), I solved the problem by conditionally including one of 2 different versions of the Product-tag. Of which only one had the UpgradeCode defined.

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <?include Config.wxi?>
  <?if $(var.IsExternalRelease) = yes?>
  <Product Id="$(var.ProductID)" Name="$(var.ProductName)" Language="1033" Version="$(var.Version)" Manufacturer="$(var.Manufacturer)" UpgradeCode="$(var.UpgradeCode)">
      <Package Id="$(var.PackageID)" InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
        <MajorUpgrade AllowSameVersionUpgrades="yes" DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
        <MediaTemplate EmbedCab="yes"/>
    <PropertyRef Id="AllProperties"/>
    <UIRef Id="CUSTOM_UI"/>
    <FeatureRef Id="F_AllFeatures"/>
    </Product>

  <?else?>
  <Product Id="$(var.ProductID)" Name="$(var.ProductName)" Language="1033" Version="$(var.Version)" Manufacturer="$(var.Manufacturer)">
    <Package Id="$(var.PackageID)" InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
    <MediaTemplate EmbedCab="yes"/>
    <PropertyRef Id="AllProperties"/>
    <UIRef Id="CUSTOM_UI"/>
    <FeatureRef Id="F_AllFeatures"/>
  </Product>
  <?endif?>
</Wix>

Because I made an effort in splitting the wix code into several pieces and referring them from the Product tag, there was not much duplication of code.