Use variables from .wxs file in wix Bootstrapper theme file - wix

In my bootstrapper Theme.xml I want to reference a path variable from a .wxs file.
In Bundle.wxs I reference certain variables using the $() syntax.
In my <BootstrapperApplicationRef> I use a ThemeFile.
From there I want to use the same variables (for example var.BundelVersionNumber). How can I achieve that?
Bundlex.wxs
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
xmlns:bal="http://schemas.microsoft.com/wix/BalExtension"
xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
<Bundle Name="MyApplication $(var.BundelVersionNumber) ($(var.Platform))"
I see that I can use some built-in burn variables, for example [WixBundleName ],:
http://wixtoolset.org/documentation/manual/v3/bundle/bundle_built_in_variables.html

You can declare a variable in your bundle and define the value based on a preprocessor variable.
<Variable Name="Platform" Value="$(var.Platform)"/>
Then you can use it in your theme.xml (or preferably your localized theme wxl ).
[Platform]

Related

Displaying MSI version parts at the Wix Burn Bundle level (to display in title / caption)

I've discovered how to access the parts within the MSI/Product tag. But my goal was to set the caption of the burn installer based on the Major/Minor version number.
This code below is the summary of what I tried to do, but this doesn't work (I think because I'm not within the Product tag).
Burn wxs:
<Wix>
<Bundle Version="!(bind.packageVersion.<packageName>)" >
<Variable Name="ProductVersionMajor" Value="!(bind.property.ProductVersion.Major)"/>
<Variable Name="ProductVersionMinor" Value="!(bind.property.ProductVersion.Minor)"/>
....
Theme.wxl:
<WixLocalization ...>
<String Id="Caption">[WixBundleName] [ProductVersionMajor].[ProductVersionMinor] Setup</String>
....
Is there some kind of work around where I can get this information at the bundle level without writing custom code?
This answer here was useful, but not quite what it appears I need; since I'm not within the WIX product tag for the inner MSI.
!(bind.property.ProductVersion.Major) is a bind variable when building an MSI, not a bundle. The available bind variables are documented at https://wixtoolset.org/documentation/manual/v3/overview/light.html. There is an open feature request for MsiPackage property bind variables at https://github.com/wixtoolset/issues/issues/4298. It would likely be additional work to get the ProductVersion.Whatever part working, so if you want that then you should add a comment to that issue.
In addition to #Sean's answer, if you are only interested in the full version and not in any breakdown of major/minor/build then the below example I have the caption in the localization WXL file can be defined as simple as:
<WixLocalization Culture="en-us" Language="1033" xmlns="http://schemas.microsoft.com/wix/2006/localization">
<String Id="Caption">[WixBundleName] Setup (v. [WixBundleVersion])</String>
...
and in my bundle.wxs file I have the following definition:
<Bundle Name="$(var.MyProductFullName)"
Version="!(bind.packageVersion.MyPackageId)"
Manufacturer="!(bind.packageManufacturer.MyPackageId)">
...
where the variable MyProductFullName is defined in my variables file under my package's installer project. So basically the [WixBundleName]
and [WixBundleVersion] are bound to the Bundle element's Name and Version attribute values, respectively.

Wix Bootstrapper (Burn) Conditional Display of Label

I am trying to diplay label "Install" or "Uninstall" based on the action being performed by the wix burn installer. So far I have tried this:
<?define InstallStatus=[WixBundleAction]?>
<?if $(var.InstallStatus) = 5?>
<Variable Name="StatusLabel" Value="Install"/>
<?else ?>
<Variable Name="StatusLabel" Value="Uninstall"/>
<?endif ?>
But it always returns Uninstall. When I checked the log file, I got Initializing string variable 'StatusLabel' to value 'Uninstall'.
When I tried to print InstallStatus, it had no value (""). Seems like it is not set till then.
Is there any other way to achieve it?
<?define InstallStatus=[WixBundleAction]?> is preprocessor code that is evaluated at compile time but WixBundleAction is a Burn variable that isn't available until runtime. In v3.x you have to write code to set a Variable at runtime. In v4, there's a new SetVariable element implemented in #4948 that allows declaratively setting the variable like you're trying to do.
If you're using wixstdba, then you probably want to know about #4149 which added support for showing a different message for install vs uninstall.

WiX standard bootstrapper application (burn) - image sizes

I'm following this extract from wixtoolset.org - Changing the WiX Standard Bootstrapper Application Branding as I'm using the HyperlinkSidebarLicense UI.
<?xml version="1.0"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
xmlns:bal="http://schemas.microsoft.com/wix/BalExtension">
<Bundle>
<BootstrapperApplicationRef Id="WixStandardBootstrapperApplication.HyperlinkSidebarLicense">
<bal:WixStandardBootstrapperApplication
LicenseUrl="License.htm"
LogoFile="path\to\customlogo.png" LogoSideFile="path\to\customsidelogo.png"
/>
</BootstrapperApplicationRef>
<Chain>
...
</Chain>
</Bundle>
</Wix>
However, I can't seem to find any reference to what size the PNG files need to be.
Has anyone worked with the bootstrapper before who can advise here?
According to the images included in the source, it looks like...
LogoFile is 64x64
LogoSideFile is 165x400
The size of these can be found in the corresponding wix theme files:
- RtfTheme.xml
- HyperlinkLicenseTheme.xml
- FoundationTheme.xml
depending on which one you are using, I'm not sure if they vary per theme but that is where the sizes are located.
Note (I believe this is a bug but I'm not sure): If you try to copy the themes into your own theme and modify theme image names at all, the wix solution will not start.
Using the properties in the WixStandardBootstrapperApplication, We also have another solution that uses a 64x64 for LogoFile but a 128x128 LogoSideFile. So once again I'm left slightly confused about WiX.
Your mileage may vary.

Nested variables in Wix

I am creating a WIX template for my projects to ensure a relatively standard layout.
I have defined a variable to reference the Main Application using <?define MainApp="MyApp"?> where MyApp is the name of the referenced project. I then use the MainApp variable to reference the project's properties in the .wxs and .wxi files.
However, I have an issue when referencing nested properties.
$var.($(var.MainApp).ProjectName) expands to "MyApp" without issue.
$var.($(var.MainApp).ProjectDir)Resources\Main.ico expands to $var.(MyApp.ProjectDir)Resources\Main.ico
$var.($(var.MainApp).TargetPath) expands to $var.(ConsoleApplication1.TargetPath)
etc...
My aim is to create a single definition for my main application, thus eliminating a search/replace, which I find clunky.
As you've found, nested preprocessor variables are not supported by the WiX toolset today.

How to define a global variable in WiX

How do I to pass in a WiX variable defined in another file (without redefining it again)?
It seems like the standard way of defining a variable is this:
<?define Var1= "****" ?>
That's right, you can define some variables in this syntax. Then include them in a separate WiX include file, with the extension .wxi. (like a .h include file), for example MyWixDefines.wxi. Then in your other WiX file Fragments, include this file, like this:
<?include MyWixDefines.wxi ?>
And finally, in the other fragments, you reference the variable like this:
<Icon Id="myIcon" SourceFile="$(var.Var1)\images\someicon.ico" />
A reminder: The variable is resolved at WiX compile time. It's not dynamically available at install time.