Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding shortcut via wixFeatures results in duplicated primary key in RemoveFile #781

Open
smoes opened this issue Apr 19, 2016 · 3 comments

Comments

@smoes
Copy link

smoes commented Apr 19, 2016

When trying to add a shortcut using wixFeaturesI get the error from light:

The primary key 'ApplicationProgramsFolderRemove' is duplicated in table 'RemoveFile'

Here is the important snippet from build.scala:

 // Adding the bat file explicitly as mentioned in the documentation
 mappings in Windows <<= (sourceDirectory in Windows) map { (dir) =>
   Seq((dir / "my.bat") -> "bin/my.bat")
},

// Adding the wanted wixFeature:
 wixFeatures += WindowsFeature(
    id = "shortcuts",
    title = "Shortcuts in start menu",
    desc = "Add shortcuts for execution and uninstall in start menu",
    components = Seq(
      AddShortCuts(Seq("bin/my.bat"))
    )
)

Am I doing something wrong or is that a bug?
Using WiX toolchain v3.5 at the moment.

@smoes smoes changed the title Adding shortcut via wixFeatures results in duplicated primary key Adding shortcut via wixFeatures results in duplicated primary key in RemoveFile Apr 19, 2016
@muuki88
Copy link
Contributor

muuki88 commented Apr 19, 2016

Sorry for the issues with windows. We have very few windows user, so this part of native-packager isn't as shiny as the other stuff. We already had some small fixes around these duplicated key issues, but looks like there still more.

Are you familiar with wix? If you are willing to make a pull request, we can surely help you to get things up and running. Starting point would be the WixHelper.scala and the WindowsPlugin

@smoes
Copy link
Author

smoes commented Apr 20, 2016

Thank you @muuki88 for the fast response.

I am not too familiar with WiX. However, it seems like this is a bug in the plugin itself. I suppose that there is always one AddShortCuts processed in makeComponentInfo, no matter if there is one explicitly added or not. This always appears in the corresponding .wix file as follows:

<DirectoryRef Id="ApplicationProgramsFolder">
  <Component Id="shortcut_d074a9b9_045a_4f82_9363_7cc797820d6b177694507" Guid="aeb3fd7b-e20f-421d-ab49-0f82c48de7c0">
    <!-- Shortcut would be here, but no targets defined -->   
    <RemoveFolder Id="ApplicationProgramsFolderRemove" Directory="ApplicationProgramsFolder" On="uninstall"/>
     <RegistryValue Root="HKCU" Key="Software\active-group &lt;someofus@active-group.de&gt;\equals-web" Name="installed" Type="integer" Value="1" KeyPath="yes"/>
   </Component>
</DirectoryRef>

If an explicit AddShortCuts is defined in the settings, the code is executed twice, one generating the above empty structure and another generating the following code (which is what we want because it actually contains a shortcut ;) ):

<DirectoryRef Id="ApplicationProgramsFolder">
  <Component Id="shortcut_695afaf8_76c7_4c4c_9699_5f193789c13d699030304" Guid="e063ab3a-8ecd-4c21-916c-96e4c036d35a">
    <Shortcut Id="shortcut_695afaf8_76c7_4c4c_9699_5f193789c13d699030304_SC1" Name="my_bat" Description="Edit configuration file: my.bat" Target="[INSTALLDIR]\bin\my.bat" WorkingDirectory="INSTALLDIR"/>
    <RemoveFolder Id="ApplicationProgramsFolderRemove" Directory="ApplicationProgramsFolder" On="uninstall"/>
    <RegistryValue Root="HKCU" Key="Software\active-group &lt;someofus@active-group.de&gt;\equals-web" Name="installed" Type="integer" Value="1" KeyPath="yes"/>
  </Component>
</DirectoryRef>

However, such a snippet should not appear twice in the WiX-file and that causes the conflict. Why the generating code is called twice, I can not say.

@muuki88 muuki88 added the bug label Apr 21, 2016
@smoes
Copy link
Author

smoes commented Jun 1, 2016

I started to dig into the problem (sbt dsl is pure pain):

The thing is, that there is one WixFeature object containing AddShortCut created based on a file's path conf/application.ini and another created by the user as described above. Both get processed in WixHelper.makeComponentInfo and for each an entry with the id ApplicationProgramsFolderRemove is created. This id is the duplicate key. It seems like one single WixFeature is meant to hold all shortcuts, not multiple one shortcut each. This is a little odd because by design the description and ids are located in WixFeature.

There are several solutions:

  • Merge all WixFeatures containing shortcuts into one, containing all. Find a generic description for that and override the user description. This way the user would be safe, even if he created several WixFeatures that contain AddShortCut
  • Is there a reason for application.ini being present in the start menu? It seems all config files in the folder conf are meant to get one. Why isn't that left to the user? I propose removing this automatism.

Best, Simon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants