Search code examples
wixshortcut-file

WiX tool - unable to add a desktop shortcut


I have created an installer of a c# application. Now I want to add a Desktop shortcut: I have followed the WiX official documentation as well as the other suggested answers on this site but still my installer doesn't create the shortcut. No errors occur during the compilation. My .wsx file is the following:

    <Directory Id="TARGETDIR" Name="SourceDir">
    <Directory Id="ProgramFilesFolder">
     <Directory Id="APPLICATIONROOTDIRECTORY" Name="Myapp">
      <Component Id="Trojan2CostCalculator.exe" Guid="*">
        <File Id="Myapp.exe" Source="$(var.Myapp.TargetPath)" KeyPath="yes" Checksum="yes"/>
        </Component>
            <Directory Id="DesktopFolder" Name="Desktop">
        <Component Id="ApplicationShortcutDesktop" Guid="*">
          <Shortcut Id="ApplicationDesktopShortcut"
                    Name="Myapp"
                    Description="Made by me"
                    Target="$(var.Myapp.TargetPath)Myapp.exe"
                    WorkingDirectory="APPLICATIONROOTDIRECTORY" />
          <RemoveFolder Id="DesktopFolder" On="uninstall"/>
          <RegistryValue
                    Root="HKCU"
                    Key="Software\Myapp"
                    Name="installed"
                    Type="integer"
                    Value="1"
                    KeyPath="yes" />
        </Component>
      </Directory>

...

and I have added the component:

    <Feature Id="MainApplication" Title="Main Application" Level="1">
  <ComponentRef Id="ApplicationShortcutDesktop"/>
    </Feature>

The installation succesfully completes but no shortcut is created. What am I missing?


Solution

  • I think your Shortcut's 'Target' is wrong. You're passing it the build time source path. It should be something like "[APPLICATIONROOTDIRECTORY]Myapp.exe". See - wixtoolset.org/documentation/manual/v3/xsd/wix/shortcut.html