Reputation: 3585
Disclaimer : I've been forced to jump ship from my favorite tried and true VS Setup project to WIX by a project requirement which, to my knowledge the VS Setup Project cannot fulfill (as described here). As such, I'm really, really new with WIX so this is probably a very "duh" question.
Trying to take it slow, I'm learning how to create shortcuts to the primary executable on the desktop and Program Files Menu. I've found how to create a component, and have stuck it in the ComponentGroup which will contain the main files (probably a wrong move right off) so this is what I have so far:
<Fragment>
<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
<!-- TODO: Remove the comments around this Component element and the ComponentRef below in order to add resources to this installer. -->
<Component Id="CMP_FooSetup">
<File Id="FILE_Foo.exe" Source="$(var.Foo.TargetPath)" KeyPath="yes"/>
</Component>
<Component Id="ApplicationShortcut">
<Shortcut
Id="FooShortcut"
Name="Foo"
Description="Foos your Bar."
Target="[#FILE_Foo.exe]"
WorkingDirectory="APPLICATIONROOTDIRECTORY"/>
<RegistryValue
Root="HKCU"
Key="Software\FooCompany\Foo"
Name="installed" Type="integer" Value="1"
KeyPath="yes"/>
<RemoveFile Id="RemoveFooShortcut" Name="Foo.lnk" On="uninstall"/>
</Component>
</ComponentGroup>
I want one shortcut to go to the desktop, and another to go to a Program Menu shortcut. To that end, I've defined the following folder structures :
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramMenuFolder">
<Directory Id="ApplicationProgramsFolder" Name="FooBar">
<!--This is where a shortcut should be placed. How? -->
</Directory>
</Directory>
<Directory Id="DesktopFolder">
<!--This is where a shortcut should be placed. How? -->
</Directory>
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLPARENT" Name="FooBar">
<Directory Id="INSTALLFOLDER" Name="Foo"/>
</Directory>
</Directory>
</Directory>
Everything in my bones and experience as a programmer (limited though it may be) screams "Hey, I should be able to use the ID of the Shortcut Component within the directory structures to instruct the installer to create these shortcuts!", but I do not know how to do that. It seems like it should be fairly rudimentary but my search has turned up nothing.
Is this possible? If so; how? If not; what should I do to make this work?
Please be kind...
Upvotes: 1
Views: 1005
Reputation: 1965
It is not possible to use a component in multiple places (directories). The alternative is to create multiple components moving the Directory
attribute from the ComponentGroup
to the Component
tag.
<ComponentGroup Id="ProductComponents">
<Component Id="CMP_FooSetup" Directory="INSTALLFOLDER">
<File Id="FILE_Foo.exe" Source="$(var.Foo.TargetPath)" KeyPath="yes"/>
</Component>
<Component Id="ApplicationShortcut" Directory="INSTALLFOLDER">
<Shortcut
Id="FooShortcut"
Name="Foo"
Description="Foos your Bar."
Target="[#FILE_Foo.exe]"
WorkingDirectory="APPLICATIONROOTDIRECTORY"/>
<RegistryValue
Root="HKCU"
Key="Software\FooCompany\Foo"
Name="installed" Type="integer" Value="1"
KeyPath="yes"/>
<RemoveFile Id="RemoveFooShortcut" Name="Foo.lnk" On="uninstall"/>
</Component>
<!-- Here I added the Directory attrib and changed the Id. -->
<Component Id="DesktopShortcut" Directory="DesktopFolder">
<Shortcut
<!-- New Id -->
Id="FooShortcutDesktop"
Name="Foo"
Description="Foos your Bar."
Target="[#FILE_Foo.exe]"
WorkingDirectory="APPLICATIONROOTDIRECTORY"/>
<RegistryValue
Root="HKCU"
Key="Software\FooCompany\Foo"
<!-- New Name -->
Name="installed_desktop" Type="integer" Value="1"
KeyPath="yes"/>
<!-- New Id -->
<RemoveFile Id="RemoveFooShortcutDesktop" Name="Foo.lnk" On="uninstall"/>
</Component>
</ComponentGroup>
As you asked, it is possible to change the wxs to include the component inside the Directory
tag, like this:
...
<Directory Id="DesktopFolder">
<Component>
<Shortcut ... />
</Component>
</Directory>
...
Upvotes: 1