Vinay
Vinay

Reputation: 285

Wix Instance Transform Dynamic ProductName and Id

I have a Wix wxs file where i have configured to have multiple instance using Instance Transform.

    <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <?define WixDemoWPFApp_TargetDir=$(var.WixDemoWPFApp.TargetDir)?>
    <Product Id="*" Name="WixSetupWPFApp" Language="1033" Version="2.0.0.0" Manufacturer="Licence Owner"
       UpgradeCode="ae4af8f5-9287-408a-b7bd-d2fdb89a8da7">
    <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />

    <MajorUpgrade DowngradeErrorMessage="Downgrade not allowed" />
    <MediaTemplate />

    <Property Id="INSTANCEID" Value="0" />

    <InstanceTransforms Property="INSTANCEID">
    <Instance Id="I01" ProductCode="{888F3620-F2AB-4C0B-A276-0A5AE9C0B6CB}" ProductName="WixDemo 3.7.4 Dev" />
    <Instance Id="I02" ProductCode="{01D23E62-A369-43E1-914A-FA017B1EE822}" ProductName="WixDemo 3.7.4 Test" />
    <Instance Id="I03" ProductCode="{00D804D7-0AD0-412C-805A-4D37FF74FFA3}" ProductName="WixDemo 3.7.5" />
    <Instance Id="I04" ProductCode="{6C3E5B4E-BF7D-4E7E-A62A-B7DFB750F581}" ProductName="WixDemo 3.7.6" />

   </InstanceTransforms>

   <Feature Id="ProductFeature" Title="WixSetupWPFApp" Level="1">
  <ComponentGroupRef Id="ProductComponents" />
  </Feature>
  </Product>

  <Fragment>

 <SetDirectory Id="WINDOWSVOLUME" Value="[WindowsVolume]" />
 <Directory Id="TARGETDIR" Name="SourceDir">
  <Directory Id="WINDOWSVOLUME">
    <Directory Id="WixDemo" Name="WixDemo">
      <Directory Id="INSTALLLOCATION" Name="WixDemo" />
    </Directory>
  </Directory>
 </Directory>

  <Fragment>
  <ComponentGroup Id="ProductComponents" Directory="INSTALLLOCATION">
  <Component Id="WixDemoWPFApp.exe" Guid="42907ee1-2bb2-4416-8d8f-cebc2bf53f09">
    <File Id="WixDemoWPFApp.exe" Name="WixDemoWPFApp.exe" Source="$(var.WixDemoWPFApp_TargetDir)WixDemoWPFApp.exe" />
  </Component>
  <Component Id="WixDemoWPFApp.exe.config" Guid="ed8a9503-2eb1-4f49-b7f3-f027f542c93f">
    <File Id="WixDemoWPFApp.exe.config" Name="WixDemoWPFApp.exe.config"
          Source="$(var.WixDemoWPFApp_TargetDir)WixDemoWPFApp.exe.config" />
  </Component>
  <Component Id="WixDemoWPFApp.pdb" Guid="5bf6cd62-7bc7-42cd-839a-7b66d7e8a09a">
    <File Id="WixDemoWPFApp.pdb" Name="WixDemoWPFApp.pdb" Source="$(var.WixDemoWPFApp_TargetDir)WixDemoWPFApp.pdb" />
  </Component>
  </ComponentGroup>
</Fragment>
</Wix>

And i install by executing the following command,

msiexec INSTALLLOCATION="D:\Wixtestinstance\1" /i WixSetupWPFApp.msi MSINEWINSTANCE=1 TRANSFORMS=":I01"
  1. How can i generate the Instance Dynamically through command without initializing inside InstanceTransform.
  2. If above is not possible can the ProductName be passed dynamically through command without Hardcoding it.

Upvotes: 1

Views: 2571

Answers (2)

RonnieScotland
RonnieScotland

Reputation: 180

Yes - it is possible to change the ARP ProductName by simply setting the ProductName in your Wix source file.

I'm doing this for multiple instances where I set the ProductName value according to the INSTANCENAME property that itself gets set as a result of a c# custom action:

<Property Id ="INSTANCEID" Value ="_" Secure ="yes"/>
<Property Id ="INSTANCENAME" Secure ="yes"></Property>

<InstanceTransforms Property ="INSTANCEID">
  <Instance Id ="I01" ProductCode ="*" UpgradeCode ="{GUID}" ProductName ="I01"/>
  <Instance Id ="I02" ProductCode ="*" UpgradeCode ="{GUID}" ProductName ="IO2"/>
  <Instance Id ="I03" ProductCode ="*" UpgradeCode ="{GUID}" ProductName ="IO3"/>
</InstanceTransforms>

<SetProperty Id ="ProductName" Before ="LaunchConditions" Value ="[INSTANCENAME]"></SetProperty>

In the Custom Action:

    session["INSTANCENAME"] = "_" + session["INSTANCENAME"];

The ProductName ="I01" in the InstanceTransforms will get replaced by the SetProperty call.

True, this name will not be the one displayed on the uninstall dialog - but maybe that's ok? For me the most important thing was to have a decent instance name in the ARP area.

Upvotes: 1

Michael Urman
Michael Urman

Reputation: 15905

Instance transforms must be created ahead of time. While technically nothing prevents a bootstrap from generating transforms dynamically at installation time just before invoking the MSI, multiple practical concerns do prevent this.

  • An instance transform must claim an InstanceId and change the ProductCode. If you do not generate these ahead of time, you do not statically know what they are so it becomes nearly impossible to query for them later through the standard mechanisms.
  • Component rules still apply, and involving instance transforms makes the implications much harder to think through. Doing so on the fly prevents creating separate components for each instance, except perhaps dynamically in the transform.
  • ProductName must be changed by a transform. While this doesn't subject you to the same identification problems as generating new GUIDs, any transforms generated on the fly will not be signed. Thus using them will affect the UAC prompt, if any, shown by Windows Installer.

Of these, only the digital signature problem is likely to be insurmountable. But the potential problems covered by the other concerns are really hard to get right.

Upvotes: 2

Related Questions