WIX - Rename shortcut in MSP

328 Views Asked by At

I am not that experienced with WiX and I am having a problem when renaming a shortcut during update via MSP. In my previous MSI I have created a desktop shortcut using the following

<DirectoryRef Id="TARGETDIR">
  <Directory Id="DesktopFolder" Name="Desktop">
    <Component Id="MyShortcut" Guid="38EF1A86-5D1B-4D78-AD66-DD1AA6635A9B" Win64="$(var.Variables_Win64)" MultiInstance="no">
     <Shortcut Id="MyShortcut"
                  Directory="DesktopFolder"
                  Icon="MyIcon"
                  Name="My Application"
                  Description="Runs my application"
                  Target="[URL]" />
      <RemoveFolder Id='DesktopFolder' On='uninstall'/>
    </Component>
  </Directory>
</DirectoryRef> 

In my MSP I want to rename the schortcut as such

<DirectoryRef Id="TARGETDIR">
  <Directory Id="DesktopFolder" Name="Desktop">
    <Component Id="MyShortcut" Guid="38EF1A86-5D1B-4D78-AD66-DD1AA6635A9B" Win64="$(var.Variables_Win64)" MultiInstance="no">
     <Shortcut Id="MyShortcut"
                  Directory="DesktopFolder"
                  Icon="MyIcon"
                  Name="My New Application"
                  Description="Runs my new application"
                  Target="[URL]" />
      <RemoveFolder Id='DesktopFolder' On='uninstall'/>
    </Component>
  </Directory>
</DirectoryRef>

What I get when I run my upgrade is a new desktop shortcut as well as the orphaned old shortcut. I understand why this is happening from this post why two shortcuts after Major upgrade (migration)? but I am not sure how I can work around this behaviour and either update the original shortcut name or delete the orphaned one instead. I cannot build an MSI it has to be an MSP so any advice would be welcome.

Thank you in advance ;-)

1

There are 1 best solutions below

0
On

The solution appears to be add in a RemoveFile but with the full name including extension to the shortcut. I had initially tried this approach before posting but had not specified the .lnk on the name so it did not work.

<DirectoryRef Id="TARGETDIR">
  <Directory Id="DesktopFolder" Name="Desktop">
    <Component Id="MyShortcut" Guid="38EF1A86-5D1B-4D78-AD66-DD1AA6635A9B"
               Win64="$(var.Variables_Win64)" MultiInstance="no">
     <Shortcut Id="MyShortcut"
                  Directory="DesktopFolder"
                  Icon="MyIcon"
                  Name="My New Application"
                  Description="Runs my new application"
                  Target="[URL]" />
      <RemoveFolder Id='DesktopFolder' On='uninstall'/>
      <RemoveFile Id='LegacyShortcut ' Name='My Application.lnk' On='install'/>
    </Component>
   </Directory>
</DirectoryRef>