Wix Add Desktop Icon

In this article we create Desktop Icon when MSI install application.

Please see below ๐Ÿ‘‡๐Ÿป image of Desktop Icon for reference.

Installed Desktop Icon
Figure: Installed Desktop Icon

Update [ExampleComponents.wxs]

Below image show content of ExampleComponents.wxs

ExampleComponents.wxs File
Figure: ExampleComponents.wxs File
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
  <Fragment>
    <ComponentGroup Id="ApplicationComponents" Directory="INSTALLFOLDER">
      <Component Directory="INSTALLFOLDER">
        <File Id="ApplicationFile" Source="WPF_Application.exe" />
      </Component>
    </ComponentGroup>
  </Fragment>
</Wix>

Add Output File

First, we need to add file for which we want to share icon.

<Component Directory="INSTALLFOLDER">
  <File Id="ApplicationFile" Source="WPF_Application.exe" />
</Component>

In above code we add output exe file.

This output file is WPF_Application.exe.

For this output file WPF_Application.exe, we want to show Desktop icon.


Add Desktop Icon

<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
  <Fragment>
    <ComponentGroup Id="ApplicationComponents" Directory="INSTALLFOLDER">
      <Component Directory="INSTALLFOLDER">
        <!--Add output file-->
        <File Id="ApplicationFile" Source="WPF_Application.exe">
          <!--Add Desktop Shortcut-->
          <Shortcut Id="DesktopShortCut"
                    Directory="DesktopFolder"
                    Advertise="yes"
                    Icon="icon.exe"
                    Name="!(bind.Property.ProductName)" />
        </File>
      </Component>
    </ComponentGroup>
  </Fragment>
</Wix>

In above code sample, we โ€œAdd Desktop Shortcutโ€.

For this we use <Shortcut> tag.

Please see below ๐Ÿ‘‡๐Ÿป code for reference.

Add Desktop Shortcut Tag
Figure: Add Desktop Shortcut Tag

After adding <Shortcut> tag, we define some properties of <Shortcut> tag.

Please see below list of properties for <Shortcut> tag.

Shortcut Properties
Property NameProperty Description
Id Identifier for this tag, by which we can refer to this tag.
Directory Special Id, which define Directory where we want to show our shortcut.
Advertise Boolean variable which decide we want to advertise this shortcut or not.
Icon Id of Icon image. Please note that this is Id โ€œNOT source of icon imageโ€.
Name Name of Icon which we want to show with Icon image.

Values we used in our code.

Shortcut Property Values
Property NameValue UsedValue Comment
Id DesktopShortCut Id which I give.
Directory DesktopFolder Special Id for Desktop Folder. Since we want to create Desktop Shortcut.
Advertise yes Always โ€˜Yesโ€™ since this is the easy way.
Icon icon.exe Reference to Id of image in Package.wxs file.
Name !(bind.Property.ProductName) Bind of Shortcut name to Product Name.


[Build] Solution

Now we need to build solution as shown below.

Build Solution
Figure: Build Solution

After building solution we need to go to folder where MSI is created.

Please see below ๐Ÿ‘‡๐Ÿป image for reference.

Open MSI Folder
Figure: Open MSI Folder

Final Result

Run the MSI to install application.

Below image show final result after running installation.

Installed Desktop Icon
Figure: Installed Desktop Icon

Thatโ€™s it!!!

Hope this post helps you.

If you like the post then please share it with your friends also.

Do let me know by you like this post or not!

Till then, Happy learning!!!