Syntax for guids in WIX?

Component GUIDs: On Component GUIDs and when they should change: Change my component GUID in wix?


Auto-guids and default attribute values

In addition to Bob Arnson’s advice:

  • Recent versions of Wix allows GUIDs to be auto-generated for several things, most significantly component GUIDs. It also covers package-, product- and patch-codes.
  • It also allows skipping some, or even most attribute values from explicit definition since most of them can be defaulted to predictable values. See code snippet below for an example.
  • Auto generating component GUIDs is possible because component GUIDs should remain the same once created unless the installation path is changed – this is described in this stackoverflow post. Accordingly Wix calculates a GUID based on the target path and other factors.
  • Product, package and patch code can generally be randomly created as they are simply supposed to be unique.
  • Note that an upgrade code is special – it should not be auto generated. It is generally desired to remain stable between releases and even between different editions and languages of the software in some cases – this depends on application design and how editions are implemented (you can use different upgrade codes and still implement a major upgrade, but the upgrade table gets complicated).
  • As a rule of thumb upgrade code identifies a “family of related products“, product code identifies an installed edition of some kind and package code identifies a unique file. Two files with the same package code is by definition treated as the same file (this can case mysterious errors – make sure to always auto-generate the package code).
  • Check the Wix documentation for details on the auto-generated GUIDs.

Simplified Wix XML Source Files

Used correctly these auto-generated GUIDs can significantly simplify your Wix source files:

<!-- Sample guid below, do not copy paste -->
<Component Id="File.dll" Guid="{12345678-1234-1234-1234-123456789ABC}">
  <File Id="File.dll" Name="File.dll" KeyPath="yes" Source="..\File.dll" />
</Component>

versus

<Component>
  <File Source="..\File.dll" />
</Component>

Taken together, the combination of auto-guids and the default attribute values yield Wix XML source files that are shorter and easier to read due to the removal of a lot of “noise” – this arguably makes them less error prone:

  • terser source files are easier to maintain and less error prone since it is easier to see what changes with diff tools and the less text exists, the less errors can hide
  • along the same lines, copy and paste of existing XML elements can cause difficult to find errors due to incomplete update of all attributes. Fewer attributes, fewer errors. I copy and paste a lot when using Wix “manually” (not using XML generators). Note that most errors are picked up by the Wix compiler and linker, but errors can still hide.
  • any changes to the default values can then be picked up auto-magically from the compiler and the linker making them propagate easier to MSI files everywhere that have been built with Wix. It is always good to keep your source files as simple as possible, but no simpler
  • overridden defaults also stand out in the source file, and you can add comments to explain why the non-default value is needed

Other Wix tips here, though the article may be a bit dated.

Leave a Comment