— New online course!  Getting Started with Azure DevOps — Special launch price 50% off —

WiX Shortcut Points to the Wrong File

by

I ran into an interesting bug/feature/problem with my WiX 3.0 / Votive installer recently where shortcuts were pointing to the wrong file.  For example in the case of Dubbelbock TFS, I set up a shortcut to Dubbelbock.UI.exe from Startup and from “Benjamin Day Consulting, Inc” in the Programs menu.  What was happening was that rather than starting up Dubbelbock.UI.exe when I logged into my machine, I got Dubbelbock.UI.exe.config popping up in notepad.  (Not exactly what I wanted.)

Here’s some sample WiX that has the same problem:

<Component Id=”ProductComponent” Guid=”05459650-55cc-4abf-9c6a-f836dc0caef8″>
    <File
        Id=”ClipboardUtility.exe.config”
        Name=”ClipboardUtility.exe.config”
        Vital=”yes”
        Source=”$(var.ClipboardUtility.TargetDir)ClipboardUtility.exe.config” />
    <File Id=”ClipboardUtility.exe”
          Name=”ClipboardUtility.exe” Vital=”yes”
          Source=”$(var.ClipboardUtility.TargetDir)ClipboardUtility.exe” >
        <Shortcut
            Id=”startmenuClipboardUtil”
            Directory=”ProgramMenuDir”
            Name=”Clipboard Utility”
            WorkingDirectory=”INSTALLDIR”
            Icon=”ClipboardUtilityIcon.ico” Advertise=”yes” />
        <Shortcut
            Id=”autostartClipboardUtil”
            Directory=”StartupFolder”
            Name=”Clipboard Utility”
            WorkingDirectory=”INSTALLDIR”
            Icon=”ClipboardUtilityIcon.ico”  Advertise=”yes” />
    </File>
    <File Id=”ClipboardUtilityIcon” Name=”C.ico” DiskId=”1″
        Source=”$(var.ClipboardUtility.ProjectDir)C.ico” Vital=”yes” />
</Component>

Looking at that code, the <shortcut> elements are contained inside of the <file></file> element for ClipboardUtility.exe so you’d think that it would create two shortcuts to ClipboardUtility.exe.  Nope.  It creates two shortcuts to “ClipboardUtility.exe.config”.

After playing around with it for a while, I figured out that the <Shortcut> directives will always create shortcuts to the first <File> in the <Component> rather than the <File> that contains the <Shortcut>.

So…the moral of the story is always put your <File>’s with <Shortcut>’s first in your <Component>.

<Component Id=”ProductComponent” Guid=”05459650-55cc-4abf-9c6a-f836dc0caef8″>
    <File Id=”ClipboardUtility.exe”
        Name=”ClipboardUtility.exe” Vital=”yes”
        Source=”$(var.ClipboardUtility.TargetDir)ClipboardUtility.exe” >
          <Shortcut
            Id=”startmenuClipboardUtil”
            Directory=”ProgramMenuDir”
            Name=”Clipboard Utility”
            WorkingDirectory=”INSTALLDIR”
            Icon=”ClipboardUtilityIcon.ico” Advertise=”yes” />
          <Shortcut
            Id=”autostartClipboardUtil”
            Directory=”StartupFolder”
            Name=”Clipboard Utility”
            WorkingDirectory=”INSTALLDIR”
            Icon=”ClipboardUtilityIcon.ico”  Advertise=”yes” />
    </File>
    <File
      Id=”ClipboardUtility.exe.config”
      Name=”ClipboardUtility.exe.config”
      Vital=”yes”
      Source=”$(var.ClipboardUtility.TargetDir)ClipboardUtility.exe.config” />
    <File Id=”ClipboardUtilityIcon” Name=”C.ico” DiskId=”1″
      Source=”$(var.ClipboardUtility.ProjectDir)C.ico” Vital=”yes” />
</Component>

-Ben


2 Responses to "WiX Shortcut Points to the Wrong File"
  1. Ben, Anna,
    Thanks for the help. I’ve been fighting with this for 2 hours and couldn’t figure out why it wouldn’t post to the right file. This worked!!

    Thanks!!

  2. Thank you, thank you, thank you, thank you, thank you, thank you, thank you, thank you, thank you, thank you.

    This problem drives me crazy!!! Finally my installer is working!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: