Windows Installer Basics: Formatted Strings |
Some table columns support formatting which can be used to replace "codes" (variables) with their contents, the following describes the basics only see the SDK doco for more information.
Code | Description |
---|---|
Replaced with the property's value. Unmatched brackets ignored.
If the "PropertyName" is invalid then the string is left
in place, if the property is null (empty) an empty string is used.
remember that property names are case sensitive and only
public (upper case) properties can be specified on the command line.
You should also have a look at the "Sample Properties" section. You can of course create your own properties (for example with FileFind or RegistryRead). See the "trailing slash removal" example for how an existing property is modified (in this case you don't want a slash on the end of a file's path). |
|
Works much like propery replacement above, this value is replaced
with the installtime directory's value
(which always ends with a "\", need to trim with a custom action if this is an issue).
In actual fact this is property replacement as Windows Installer creates properties for directory keys which allows their values to be specified on command lines etc. | |
Replaced with the environment variables value. | |
Replaced with the filename of the specified file (long format). | |
Replaced with the filename of the specified file (8.3 format). Note that this format only returns the 8.3 formatted file name for the "Value" column in the "Registry" or "IniFile" tables, otherwise the long format is used (as if "[#FileKey]" were used). | |
Replaced with the components installation directory. This can evaluate to a empty string in some circumstances. | |
Replaced with the character specified, can be used to enter brackets
and other difficult characters that might otherwise cause a
"BADFORMATTED" (Windows Installer) error.
See escaping square brackets for a common use of this code. |
|
Replaced with a null character (0x00). This is used to author REG_MULTI_SZ character strings in the "Registry" table. Note that "[~]" is also used to append or prefix values to environment variables using the "Environment" table. |
There are restrictions on where some of the above codes can be used, please see the SDK doco for more information.
You will have issues with some commands if the field requires a formatted value and your text includes left or right square brackets, the "$$WI_FMT" transformation is the easiest way to automatically handle this.
Test the use of any formatting well, including tests for:
I recommend that if you use the "Path" command that you check the relevant environment variables after each of the tests, see:
For backwards compatability reasons some MAKEMSI commands support Windows Installer formatting by default while others like the "registry" command don't (and use the MSIFORMATTED" parameter to turn it on).
BADFORMATTED - Incorrectly Formatted Strings |
If incorrect MSI formatting is supplied to a table column that supports formatting then Windows Installer will complain with something similar to:
... REASON ~~~~~~~ Windows Installer has reported that 1 column(s) in a "Registry" table record failed "FIELD" validation: * #1 "Value": (BADFORMATTED) An invalid formatted string was supplied. You probably need to "escape" characters such as curley or square brackets (encode "[" as "[\[]" etc). Contents of the Problem Record (table "Registry") ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Registry (s72) = RegKey803 Root (i2) = 0 Key (l255) = VisualStudio.inc.8.0 Name (L255) = <<null string>> (OK: nulls allowed in this column) Value (L0) = PHP ŸCŸ"ŸNŸ<?[Ÿh ŸXŸNŸSŸvŸgŸtŸ@ŸCŸ< Component_ (s72) = C_INC_FILETYPE
In the above Japanese text the "[" character needs to be replaced with "[\[]" (that is it needs to be escaped as documented above).
As the registry" command was most likely used to generate the failing table manipulation, you can also use its "MSIFORMATTED" parameter to tell it that the text you passed was unformatted and MAKEMSI will do any required character escaping for you.
An example of a command that will generate this sort of error is:
<$Component "INI" Create="Y" Directory_="<$AnyDir>" LM="Y"> <$IniFile "Dennis.INI" DIR="INSTALLDIR"> <$IniSection "Section1"> <$Ini "Key1" Value="Some [value"> <$/IniSection> <$/IniFile> <$/Component>
To correct it change the "ini" command to:
<$Ini "Key1" Value="Some [\[]value">
Some other links about this or similar issues:
Alternatives |
Note that not all Windows Installer columns support MSI formatting. With other tools, MSI formatting is the only way to insert replaceable information, this is not the case with MAKEMSI as a lot of information can be determined or is known and generally available in PPWIZARD macros, some examples follow: