14

I need to use variable in WIX localization file WIXUI_en-us.wxl. I tried use it like this:

<String Id="Message_SomeVersionAlreadyInstalled" Overridable="yes">A another version of product $(var.InstallationVersionForGUI) is already installed</String>

But it doesn't work. And when I declared property and used it this way:

<String Id="Message_SomeVersionAlreadyInstalled" Overridable="yes">A another version of product [InstallationVersionForGUI] is already installed</String>

doesn't work either.

Where was I wrong?

Thanks for help and your time.

4 Answers 4

19

Localization strings are processed at link time, so you can't use $(var) preprocessor variables. Using a [property] reference is supported, as long as the place where the localization string is used supports run-time formatting (e.g., using the Formatted field type).

3
16

Your second method should work just fine. This is the same method used by the default .wxl files.

For example, in your .wxl file you would declare your string:

<String Id="Message_Foo">Foo blah blah [Property1]</String>

And in your .wxs file, you declare the property. If you wish, you can declare the property to match a WiX variable (which it sounds like you're trying to do)

<Property Id="Property1">$(var.Property1)</Property>
6
  • Strange, now this method works. I don't know what was wrong, but thank you anyway!
    – Elena
    Jul 27, 2011 at 9:21
  • Does not work for me, Message_Foo as accessed with !(loc.Message_Foo) still returns the static unevaluated string for me, being literally "Foo blah blah [Property1]". Where exactly do you define the property?, it was in the main wxs file after the Package element in my case ...
    – Cel
    Apr 26, 2012 at 18:36
  • @Cel properties are case sensitive, thats about the only issue I can think of unless you're not referring to items in the String table. May 9, 2012 at 4:40
  • I found a somewhat disappointing answer on wix users mailing list: "That means you're trying to use properties in a string that isn't formatted." - seems like it is not possible to properly template Wix localization files at the moment as a lot of the targets are not formatted; and you need to take the use targets into account rather than the evaluations always working ...
    – Cel
    May 9, 2012 at 12:38
  • 2
    @cel that specific answer on the mailing list is a little vague, if you know the property at build time you can just combine wix variables and localizations... e.g. <Product Id="*" UpgradeCode="$(var.Property_UpgradeCode)" Name="!(loc.ApplicationName) $(var.versionmajor)" Language="!(loc.Property_ProductLanguage)" Version="$(var.version)" Manufacturer="!(loc.ManufacturerName)" > May 16, 2012 at 1:44
1

Preprocessor variables $(var.VariableName) are are processed at link time, so ideally you would use [PropertyName] which would be defined on the main Product element.

The issue sometimes is that property is not yet defined, for instance using the product name on the localization file seems not posible.

This solution was done aiming to only type the product name once given "Super product" as product name:

  • In case of running through visual studio extension:
    • Project properties -> Build -> Define variables -> "MyProductName=Super product" (No quotes)
  • In case of runing from cmd or some other place:
    • On Light.exe, add -d"MyProductName=Super product"

Into the localization .wxl file:

<String Id="Description" Overridable="yes">Description of !(wix.MyProductName) 
 to make it more interesting</String>

I have an aditional config file .wxi I include on other files to have some vars, for instance, here i had hardcoded the value but now it's harcoded on the variable definition and I use the given value:

<?xml version="1.0" encoding="utf-8"?>
<Include>
    <!-- Define the product name preprocesor variable -->
    <?define ProductName="!(wix.ProductNameDefVar)" ?>
    <!-- From this point, can use the preprocesor var -->
    <?define ProductName_x64="$(var.ProductName) (64bit)" ?>
    <?define ProductName_x32="$(var.ProductName) (32bit)" ?>
    <?define CompanyDirName = "My company name" ?>
</Include>

Finally, the place where the localization value where the localization text was not interpolating, is like this:

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

  <!-- Include the config file with the preprocesor var -->
  <?include $(sys.CURRENTDIR)\Config.wxi?>
 
  
  <!-- Main product definition -->
  <Product  Id="$(var.ProductCode)"
    Name="$(var.ProductName)"
    Language="!(loc.Language)"
    Version="$(var.BuildVersion)"
    Manufacturer="!(loc.Company)"
    UpgradeCode="$(var.UpgradeCode)">
    
    <!-- Package details -->
    <!-- Here, Description was not interpolating -->
    <Package InstallerVersion="200"
             Compressed="yes" 
             InstallScope="perMachine" 
             Platform="$(var.Platform)"
             Manufacturer="!(loc.Company)"
             Description="!(loc.Description)"
             Keywords="!(loc.Keywords)"
             Comments="!(loc.Comments)"
             Languages="!(loc.Language)"
             />
[...]
0

I was trying to get localization file to use variables. Came across this post:

There are different layers of variables in WiX (candle's preprocessor variables, Light's WixVariables/localization variables/binder variables, and MSI's properties). Each have different syntax and are evaluated at different times:

Candle's preprocessor variables "$(var.VariableName)" are evaluated when candle runs, and can be set from candle's commandline and from "" statements. Buildtime environment properties as well as custom variables can also be accessed similarly (changing the "var." prefix with other values).

Light's variables accessible from the command-line are the WixVariables, and accessing them is via the "!(wix.VariableName)" syntax. To access your variable from your commandline, you would need to change your String to: This build was prepared on !(wix.BuildMachine)

If you instead need to have the BuildMachine value exist as an MSI property at installation time (which is the "[VariableName]" syntax) you would need to add the following to one of your wxs files in a fragment that is already linked in:

Now, the environment variable COMPUTERNAME always has held the name of my build machines in the past, and you can access that this way: $(env.COMPUTERNAME). So, you can get rid of the commandline addition to light.exe and change your wxs file like this:

<WixProperty Id="BuildMachine" Value="$(env.COMPUTERNAME)"/>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.