WiX with a code example

820 views Asked by At

I am looking for a precise tutorial of WiX with a project example, if possible. Current tutorials didn't help me a lot.

My requirements are

  • Including dependencies.
  • Adding registry entries.
  • Creating folders under the application folder.
  • Adding a custom UI Dialog with browse button.
  • Creating shortcuts on the desktop and start menu.

I have Visual Studio 2008 with WiX 3.0.5419.0 installed.

1

There are 1 answers

0
liggett78 On BEST ANSWER

Creating directories

<Directory Id="TARGETDIR" Name="SourceDir">
    <Directory Id="ProgramMenuFolder">
        <Directory Id="ShortcutFolder" Name="My app">
        </Directory>
    </Directory>

    <Directory Id="ProgramFilesFolder">
        <Directory Id="My Company" Name="My Company">
            <Directory Id="INSTALLDIR" Name="My product">
            </Directory>
        </Directory>
    </Directory>
</Directory>

You can nest Directory tags as you like and after that use DirectoryRef to list components that go into this directory.

Adding a custom UI Dialog with a browse button

You can define UIRef with WixUI_InstallDir somewhere in a Fragment, Include, or Module (not in Product, despite the documentation):

<UIRef Id="WixUI_InstallDir" />

This will create a package that uses InstallDir UI, for example, the target directory can be specified in the UI (in case you mean this, otherwise you'll need to define a new dialog from scratch/copy an existing one and insert it into the sequence.)

Adding registry entries

Specify something like

<RegistryKey Action="none" Root="HKCU" Key="some key">
    <RegistryValue Value="some value" Type="string" KeyPath="yes" />
</RegistryKey>

inside a component.

Creating shortcuts on the desktop and start menu

<DirectoryRef Id="ShortcutFolder">
    <Component Id="ShortcutsComponent" Guid="{XXXX}">
        <CreateFolder Directory="ShortcutFolder" />

        <RemoveFolder Id="RemoveShorcutFolder" Directory="ShortcutFolder" On="uninstall" />

        <Shortcut Id="UninstallProduct"
                  Name="Uninstall my product"
                  Target="[System64Folder]msiexec.exe"
                  Arguments="/x [ProductCode]"
                  Directory="ShortcutFolder"
                  Description="Uninstalls my product"/>
    </Component>
</DirectoryRef>

Note the use of ShortcutFolder directory from the directory list I showed earlier.

Including dependencies

Not quite sure which dependencies you mean.

.NET Framework? Example:

<Condition Message="This setup requires the .NET Framework 3.5 or later to be installed.">
    Installed OR NETFRAMEWORK35 OR NETFRAMEWORK40FULL
</Condition>

Third-party DLLs? You just create a separate component for every DLL and specify the path where WiX should look for it using the File tag. This component then is listed under a DirectoryRef tag that specifies where the file goes during install.