Ghali Zangui
Ghali Zangui

Reputation: 21

Wix Managed bootstrapper Application: Passing variables to msi through bundle

I created a custom UI for my Wix Bundle in WPF with overriding the Bootstrapper Application Class, and I'm struggling with a variable that I need to access and modify if needed from the UI. This variable is the install folder path (string) of the msi deployed by the bootstrapper.

I followed what I found on many forums but It's not working, I can't access this variable. Here is my code:

Msi installer:

<Product ...>
  <Feature ...
           ConfigurableDirectory="INSTALLFOLDER"
           ...>
</Product>

<Directory Id="TARGETDIR" Name="SourceDir">
  <Directory Id="ProgramFilesFolder">
    <Directory Id="ManufacturerFolder" Name="...">
      <Directory Id="INSTALLFOLDER" Name="!(bind.property.ProductName)"/>
    </Directory>
  </Directory>
</Directory>

Bundle:

<Variable Name="InstallFolder" bal:Overridable="yes" />

<Chain>
      <MsiPackage ...
                  ForcePerMachine="yes"
                  Compressed="no"
                  Visible="no"
                  EnableFeatureSelection="yes"
                  Vital="yes">
        <MsiProperty Name="INSTALLFOLDER" Value="[InstallFolder]" />
      </MsiPackage>
      ...
</Chain>

C# Managed Bootstrapper Application:

if (Bootstrapper.Engine.StringVariables.Contains("InstallFolder"))
  installFolder = Bootstrapper.Engine.StringVariables["InstallFolder"];

The "installFolder" variable is always null... I really don't know what is wrong with my code. Hope someone can help me. Thank you

Edit:

I changed the bundle variable as suggested by Pavel with a default value, now even if I still can't get the value returned by the MSI, I can set Bootstrapper.Engine.StringVariables["InstallFolder"] to a value and it's passed correctly to the msi.

Upvotes: 1

Views: 6325

Answers (3)

Ghali Zangui
Ghali Zangui

Reputation: 21

Okey so thanks to Pavel I understand better now how it works:

In the wix bundle, to change an msi variable you need to set a default value, in my case it is:

<Variable Name="InstallFolder" Type="string" Value="[INSTALLFOLDER]" Persisted="yes"/>

This default value corresponds to the real default one in the msi. With that I can access this variable from my c# code and change it if needed by doing:

Bootstrapper.Engine.StringVariables["InstallFolder"] = value;

Upvotes: 1

Pavel
Pavel

Reputation: 910

If I remember it correctly, Burn variables have numeric type by default.

So, please, try to explicitly specify your variable type. You can also specify the default value:

<Variable Name="InstallFolder" Type="string" Value="[ProgramFilesFolder]!(bind.packageName.YourMsiPackageId)" Persisted="yes"/>

Probably, you should also add Persisted="yes" in order to keep the value if the installer requires reboot in the middle of the installation process.

Upvotes: 0

jbudreau
jbudreau

Reputation: 1307

The same question was answered here - Cannot read input from Bootstrapper variable in Managed Bootstrapper Application C#-Code

Short version: you also have to manually parse the command line arguments via Bootstrapper.Command.GetCommandLineArgs() and write to the Bootstrapper.Engine.StringVariables["variable"]

Upvotes: 0

Related Questions