1

I am trying to share a variable across 2 of my wix projects but I am having issues.

Basically I am trying to accomplish having the version number of my bootstrapper and MSI in one file and then this referenced by the two projects.

I have three projects

  • Install - This is a setup project that creates an .msi file
  • Bootstrapper - This is a Wix Bootstrapper project that references and runs the .msi file at runtime
  • Shared - This is a wixlib project that contains a single variable in a fragment that is the version number

The shared project contains a single file i have called GlobalVars.wxs and looks like this

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Fragment>
    <?define VersionNo = "6.86.123"?>
    </Fragment>
</Wix>

The bootstrapper references this variable like this

<Bundle Name="ProgramName" Version="$(var.VersionNo)" Manufacturer="CompanyName" UpgradeCode="Guid" Compressed="no">

and the Install project references the variable like this - and has a reference to the .wxs from the shared project

  <Product Id="*" Name="Program Name" Language="2057" Version="$(var.VersionNo)" Manufacturer="CompanyName" UpgradeCode="guid">
    <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine"  InstallPrivileges="elevated"/>
    <?include GlobalVars.wxs ?>

Both projects have references setup to the wixlib project that contains the variable

When i attempt to build I am getting this error on both the install and bootstrapper project

Undefined preprocessor variable '$(var.VersionNo)'.

If the <?include?> tag resolved the issue I would expect the install project to build

Does anyone have any ideas as to what I might be doing wrong here?

To me it looks like the variable has not been defined by the time the build attempts to call it, but I am unsure as to show to change the order to ensure the variable is defined before anything else

Thanks for the help

martpendle
  • 432
  • 4
  • 19
  • 1
    I think you are mixing pre-processing and runtime. is pre-processing, it does not create a variable. – Morten Frederiksen Sep 14 '16 at 10:37
  • Ah that would make sense! How do I make a variable then? (sorry really simple question I know!) – martpendle Sep 14 '16 at 10:47
  • 1
    You could use Windows Installer properties – Morten Frederiksen Sep 14 '16 at 13:47
  • Do you know if it is possible to define these in the WiX files rather than passing them in at run time? – martpendle Sep 14 '16 at 14:38
  • 1
    You can also do `Version="!(bind.packageVersion.MSIPackage)"` where "MSIPackage" is the Id of the `` in your bundle. Your $(var.VersionNo) isn't getting picked up because you have nothing to bring in that `` from the wxs file. Generally you need a `` tag in your product to bring in a fragment from another wxs. – Brian Sutherland Sep 14 '16 at 14:52
  • Thanks Brian, please can you explain the reference thing? I thought If i added a project reference to the shared project in the install project, the install project would have access to all the fragments? – martpendle Sep 15 '16 at 09:01
  • 1
    First thing: `` defines a pre-processor-variable to be used later on by referencing it via `$(var.VersionNo)`. Second: Just referencing a wix project doesn't help, you have to include the file with the version via ``. One more note: Variables are not put into the generated MSI file, therefore you do not see them – Stephen Reindl Sep 15 '16 at 12:16
  • Thanks Stephen, I have added this tag to the main Product.wxs file . The project that contains the Product.wxs has a visual studio reference to the project that contains the .GlobalVars file as well, but unfortunately it still does not pick up the variable. I will update the question now as well – martpendle Sep 23 '16 at 11:03
  • 1
    I'd also be keen to see an answer to this. Copy+Pasting code, even Wix code, feels wrong to me – Craig Brett Feb 22 '17 at 11:03
  • One comment states does not create a variable, then another comment by @StephenReindl says it does. Preprocess variables, Bind variables, Wix Variables, Windows Properties... this whole WiX thing seems needlessly overcomplicated with a lack of good documentation. – Brain2000 Sep 26 '18 at 00:37
  • Well, you are free to find other tools that might fot to your needs. I use several tools to create installers, but whenever it reaches a higher level of complexity I automatically start over with WiX. The complexity does not com from Wix but of the environment the software works with. – Stephen Reindl Sep 30 '18 at 18:08

1 Answers1

1

I believe the answer to this question will help. I've used it and noticed that properties seem to be usable in my main wxs file.

To summarise, you need to set up a fake componentGroup in your library fragment, and use it in your installer. You do not need the include anymore, as long as the fake componentGroup from your fragment is referenced as a componentGroupRef in your main install, and your wixlib project is referenced in your installer project through VS (you said you'd already done this in your comments above).

Your library fragment might look something like this.

<Fragment id="fragment_id_may_not_be_needed">
    <?define VersionNo = "6.86.123"?>
    <ComponentGroup Id="c.define_version_num" />
</Fragment>

If the define for whatever reason doesn't work, try using a property instead. I'd be interested to know which works. Properties seem to work for me.

Then reference it in your main install like this:

<Feature Id="Main_installation" Title="Main installation" Level="1">
  <!-- bringing in fragments from the shared libraries -->
  <ComponentGroupRef Id="c.define_version_num" />
</feature>

Give it a whirl.

Community
  • 1
  • 1
Craig Brett
  • 2,295
  • 1
  • 22
  • 27