Is it possible to pass variable to WIX localization file?

泪湿孤枕 提交于 2019-12-19 05:12:29

问题


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.


回答1:


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).




回答2:


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>



回答3:


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)"/>



来源:https://stackoverflow.com/questions/6827931/is-it-possible-to-pass-variable-to-wix-localization-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!