Automatic account creation is now enabled. Captcha authentication required for account creation and editing unless you are trusted here.

Conditional Inner Text

From WiX Wiki at MindCapers

Jump to: navigation, search

Contents

What is Inner Text?

The behavior of the several elements (Condition, Custom, et. al.) depends on "inner text". Though this concept is repeated, the syntax of this inner text isn't documented, or at least, is not documented well. Thus, here is the start of a collection of snippets that show valid inner text. I am gathering samples and going through the source code seems to be the way to go.

MSI Documentation

Here is the MSDN article that describes the conditional statement syntax for Windows Installer.

WiX v2 Tutorial

This page has wonderful information about "expressions", which is what conditional inner text is.

Operators

This list of operators was gathered from going through the WiX source code (Preprocessor.cs, v.3.0.something):

  • = (equals)
  • != (notEquals)
  • < (lessThan)
  • <= (lessThanEquals)
  • > (greaterThan)
  • >= (greaterThanEquals)
  • ~= (equalsNoCase)

Keywords

This list of keywords was gathered from going through the WiX source code (Preprocessor.cs, v.3.0.something):

  • AND
  • OR
  • NOT

Examing the parsing, it looks as if the syntax is not robust as far as white space. The following variants are explicitly checked for, it appears anything else would fail to be parsed correctly. Please note that the quotes are not part of the syntax, they are included to show exactly what the parser is looking for (from StartsWithKeyword()):

  • "NOT "
  • "NOT("
  • "AND "
  • "AND{"
  • "OR "
  • "OR("

Note that there is no space between the keyword and an optional open parenthesis.

CDATA and Why You Should Use It

Conditions are commonly contained within a
<![CDATA[  ]]>
block. This is simply because the greater-than and less-than operators have a different meaning to XML. The
<![CDATA[ 
tells XML to ignore those characters until the end of the block, terminated with
]]>
. You can also escape them using < and >.

Examples

Here are several common conditional expressions.

 
    <Condition Message="The .NET Framework 2.0 must be installed ([NETFRAMEWORK20])">
      Installed OR NETFRAMEWORK20
    </Condition>
 
    <PropertyRef Id="NETFRAMEWORK10"/>
    <PropertyRef Id="NETFRAMEWORK11"/>
    <Condition Message="The .NET Framework 1.0/1.1 cannot be installed">
      Installed OR (NOT (NETFRAMEWORK10 OR NETFRAMEWORK11))
    </Condition>
 
    <!-- Run only upon initial install -->
    <Condition Message='Blah'>COMPANYDIR AND NOT Installed</Condition>
 
    <!-- Run on initial install, repair and minor upgrade -->
    <Condition Message='Blah'>COMPANYDIR AND NOT REMOVE ~= "ALL"</Condition>
 
    <!-- Set a property value depending on the value of another property -->
    <Publish Property='B' Value='A is one'><![CDATA[A = "1"]]></Publish>  
    <Publish Property='B' Value='A is not one'><![CDATA[A <> "1"]]></Publish>
 
    <Condition><![CDATA[VersionNT<501]]></Condition>
    <Condition><![CDATA[Build<>0]]></Condition>
 

Differences from Formatted Fields

This information is correct for the condition syntax; however, if used in a formatted field, $ means the installation directory of the component (if $component is enclosed in square brackets []). ? has no meaning in a formatted field.

For more see "Formatted" in the Windows Installer SDK. The WiX documentation does indicate which fields use Formatted syntax.

Personal tools