0

I'm having trouble with replacing the installation directory of my WIX project in a custom bootstrapper project. The solution consists 3 projects (Custom Bootstrapper, Installer Project and BootstrapperSetup).

The product.wcs in the Installer Project looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<?include $(sys.CURRENTDIR)\Settings\settings.wxi ?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
     xmlns:bal="http://schemas.microsoft.com/wix/BalExtension">

<Product Id="*" Name="$(var.ProductName)" Language="1033" Version="1.0.0.0" Manufacturer="$(var.Manufacturer)" UpgradeCode="f4c5c824-17e9-4897-9af0-49b2b1225251">
<Package InstallerVersion="300" Compressed="yes" InstallScope="perMachine" />

<MajorUpgrade DowngradeErrorMessage="A newer version of $(var.ProductName) is already installed." />
<MediaTemplate />

<Property Id="PRODUCTNAME" Value="$(var.ProductName)" />
<Property Id="INSTALL_LOCATION" Value="ApplicationInstallDir"/>

<Directory Id="TARGETDIR" Name="SourceDir">
  <Directory Id="$(var.PlatformProgramFilesFolder)" Name="PFiles">
    <Directory Id="DirManufacturer" Name="$(var.Manufacturer)">
      <Directory Id="ApplicationInstallDir" Name="$(var.ProductName)">
        <Component Id="ProductComponent" KeyPath="yes" Guid="28982BC3-BCEA-4EAF-9E7E-9E19A9355CFA">
          <File Id="Norma12" Name="$(var.Norma 12.TargetFileName)" Source="$(var.Norma 12.TargetPath)" DiskId="1" />
          <CreateFolder />
        </Component>
      </Directory>
    </Directory>
  </Directory>
</Directory>

<Feature Id="ProductFeature" Title="InstallerProject" Level="1">
  <ComponentRef Id="ProductComponent" />
</Feature>

</Product>
</Wix>

The bundle.wxs looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<?include $(sys.CURRENTDIR)\Settings\settings.wxi ?> 

<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" 
 xmlns:util="http://schemas.microsoft.com/wix/UtilExtension"
 xmlns:bal="http://schemas.microsoft.com/wix/BalExtension">

<Bundle Name="$(var.ApplicationName)" Version="$(var.Version)" Manufacturer="$(var.Manufacturer)" 
      UpgradeCode="ba657b0d-46d6-452a-aa4c-4212dda03d52"
      Copyright="Copyright (c) 2013 $(var.Manufacturer). All rights reserved."
      HelpUrl="http://www.miconsultancy.com" AboutUrl="http://www.miconsultancy.com">

<BootstrapperApplicationRef Id="ManagedBootstrapperApplicationHost">
  <Payload SourceFile="$(var.MI Wix.TargetDir)\BootstrapperCore.config"/>
  <Payload SourceFile="$(var.MI Wix.TargetPath)"/>
  <Payload SourceFile="C:\Program Files (x86)\WiX Toolset v3.7\SDK\Microsoft.Deployment.WindowsInstaller.dll"/>
</BootstrapperApplicationRef>

<Variable Name="ProjectName" Type="string" Value="$(var.ApplicationName)"  />
<Variable Name="LicenseRTF" Type="string" Value="$(var.MI Wix.ProjectDir)\License\mi_lic.rtf"/>
<Variable Name="ProductID" Type="string" Value="$(var.ApplicationID)"/>
<Variable Name="varInstallLocation" Type="string" Value="\$(var.Manufacturer)\$(var.ApplicationName)"/>

<Chain>
  <!-- TODO: Define the list of chained packages. -->
  <PackageGroupRef Id='Netfx4Full' />

  <MsiPackage Compressed="yes"
              SourceFile="$(var.InstallerProject.TargetPath)"
              Vital="yes" Id="$(var.ApplicationID)" >
    <MsiProperty Name="INSTALL_LOCATION" Value="[varInstallLocation]"/>
  </MsiPackage>
    </Chain>
</Bundle>

<Fragment>
<!-- Managed bootstrapper requires .NET as a dependency, since it was written in .NET.
   WiX provides a Bootstrapper for the bootstrapper. The fragment below includes .NET.
   For more information or examples see Heath Stewart's blog or the WiX source:
   http://blogs.msdn.com/b/heaths/archive/2011/10/28/introducing-managed-bootstrapper-applications.aspx
   -->

<WixVariable Id="WixMbaPrereqPackageId" Value="Netfx4Full" />
<WixVariable Id="WixMbaPrereqLicenseUrl" Value="NetfxLicense.rtf" />

<util:RegistrySearch Root="HKLM" Key="SOFTWARE\Microsoft\Net Framework Setup\NDP\v4\Full" Value="Version" Variable="Netfx4FullVersion" />
<util:RegistrySearch Root="HKLM" Key="SOFTWARE\Microsoft\Net Framework Setup\NDP\v4\Full" Value="Version" Variable="Netfx4x64FullVersion" Win64="yes" />

<PackageGroup Id="Netfx4Full">
  <ExePackage Id="Netfx4Full" Cache="no" Compressed="yes" PerMachine="yes" Permanent="yes" Vital="yes"
              SourceFile="C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bootstrapper\Packages\DotNetFX40\dotNetFx40_Full_x86_x64.exe"
              DownloadUrl="http://go.microsoft.com/fwlink/?LinkId=164193"
              DetectCondition="Netfx4FullVersion AND (NOT VersionNT64 OR Netfx4x64FullVersion)" />
</PackageGroup>
</Fragment>
</Wix>

The variable varInstallLocation needs to changed in the custom bootstrapper, this is done with:

BootstrapperApplication.Engine.StringVariables("varInstallLocation") = s_installDirectory

But when I do the save in code, the new installation path isn't stored into the variable and the application will be installed in the default location. Could someone help me out here please.

AlexLans
  • 1
  • 1
  • 2
  • Check the bootstrapper install log at %TEMP%\BootstrapperSetup_.log. It should show the initial values of your bootstrapper variables and each change. The setup install log %TEMP%\BootstrapperSetup__.log will show the properties passed to the MsiPackage. – Tom Blodget Jun 11 '13 at 17:04

1 Answers1

0

Make sure you set the variable before calling Engine.Apply(). Variables set after that, will be not be provided to the chained packages.

Rob Mensching
  • 33,834
  • 5
  • 90
  • 130