Dynamically assigning name to shortcut at run time

2020-07-25 02:35发布

问题:

I want to assign different names to a shortcut based on user input. Is this feasible using the WiX toolset? I have tried assigning value of property to Name attribute of Shortcut element but it does not work.

回答1:

The Name column of the Shortcut Table isn't of type Formatted therefore it isn't possible to use [PROPERTY] to mutate it at runtime.

The only ways I know how to do it are:

  1. Skip the shortcut table and write a custom action to handle it yourself.
  2. Write a custom action to dynamically author the ShortCut table at runtime using SQL TEMPORARY syntax.
  3. There might be an extension out there that has implemented #2.


回答2:

I use this workaround:

<CustomAction Id="SetShortcutFolder" Return="check" Property="ProgramMenuDir" Value="[ProgramMenuFolder][PRODUCTNAME]"></CustomAction>

<!--Setting up the shortcuts for the product-->
    <Directory Id="ProgramMenuFolder" Name="Programs">
       <Directory Id="ProgramMenuDir" Name="TempName"/>
    </Directory>



<!--Set the install path to match the path of the product already installed-->
<Custom Action="SetInstallPath" Before="CostFinalize"/>

Hope this helps..:)



回答3:

If you are doing lots of translations and say lots of permutations, then this is a real drawback. Instead of using WIX (which is one of the most obfuscated API's I've ever used) you may prefer to simply write the shortcut using the Windows API.



标签: wix wix3.7