Skip to Content

Simplifying WiX component authoring

In the latest in the ongoing series of simplifying the WiX language, I recently added two new defaults to the WiX compiler:

  • The <a href="” mce_href="">Component/@Guid attribute value defaults to “*” so that if you don’t specify it, WiX generates a stable component GUID at link time. Generated component GUIDs are available as long as your component:
    • Does not contain an <a href="” mce_href="">ODBCDataSource element. (ODBwhat?)
    • Has only one file.
    • Has only registry values.
  • The Component/@Id attribute value defaults to the id of the keypath resource. The component itself cannot be the keypath for this to work (obviously, there’s no id for it to default to).

These changes will appear in the first weekly release of WiX v3.5 in 2010.

Combine the two features and a single-file component can now be as simple as:

  <File Source="foo.exe" />

In this case, the component’s id will be “foo.exe” because the File element’s default for its Id is the filename portion of the Source attribute. Call it hygenic double-dip defaulting.

A multi-file component isn’t suitable for generated GUIDs, so it requires an explicit GUID but can still take advantage of default component ids:

<Component Guid="{A5B56773-5E26-4C5F-AC51-C2470C3658AF}">
  <File Source="foo.dll" />
  <File Source="bar.dll" />
  <File Source="bob.exe" KeyPath="yes" />

In this case, the component’s id will be bob.exe from the keypath File element’s default Id. Note that unless you use the generated GUID default and live within its rules, you must specify an explicit KeyPath attribute value of yes on the resource whose id you want to be the component id.

We can’t eliminate the dread component rules but we can make it simpler to live within them.