Build an msi package for Csharp using WiX

From munkjensen.net/wiki

Preface

This page will describe in short terms how to build an msi package for an Csharp (C#) project. The resulting package will not give the end user any installation options to choose between.


Prerequisites

  • Visual Studio. I used 2015 version.
  • An C# project that does not need the end user to select install options.
  • WiX --> http://wixtoolset.org/releases/ This was written while v3.10.3 was lates stable release.
  • WaX --> In VS 2015 go to "Tools" -> "Extensions and updates", then click "Online" and in the search box type “wax”

Step by step

  1. Install WiX
  2. Install WaX
  3. Open the C# project solution you want to build an msi package for.
  4. Add a WiX setup project to the solution.
  5. Mark your solution in the solution explorer.
  6. Click "File" -> "Add" -> "New Project"
  7. Search for “Windows installer XML”
  8. Select "Setup project"
  9. Type in a name but know that this will be the filename of your msi package. I will use 'SetupProject' from now on and this will result in SetupProject.msi as filename.
  10. Click "Tools"
  11. Select "Wix Setup Editor"
  12. "Setup project to edit:" should already be filled in as "SetupProject (..\SetupProject)"
  13. As "Root directory" select "INSTALLFOLDER (SetupProject)"
  14. Select the "Projects to install" by ticking them off in the list of avilable projects in your solution.
  15. Click the + sign to the right of all the "Directory mappings"
  16. Click the + sign to the right of all the "File mappings"
  17. Make sure you see 5 green circles with a white checkmark in the WaX window, indicating that all is fine
  18. Close the WaX window on the X in top right corner.
  19. Save all file changes by pressing [CTRL + SHIFT + S] i Visual Studio.
  20. Open / Go to "Product.wxs" file in Visual Studio.
  21. Find the XML line that starts with <Product Id="*"
  22. The Manufacturer="" cannot be empty so fill in something reasonable.
  23. Find the XML line: </Feature>
  24. Before the found line; add the definitions of two new componenents - one for a start menu shortcut, one for a desktop shortcut.
    <ComponentRef Id="ApplicationShortcut" />
    <ComponentRef Id="ApplicationShortcutDesktop" />
  25. Find the directory definition lines and insert on the same level as "ProgramsFilesFolder"
    <Directory Id="ProgramMenuFolder">
        <Directory Id="ApplicationProgramsFolder" Name="MyWpfApplication"/>
    </Directory>
    <Directory Id="DesktopFolder" Name="Desktop"/>
  26. Copy this fragment in at the bottom and replace the GUID and the path of the program:
    <Fragment>
      <DirectoryRef Id="ApplicationProgramsFolder">
    	<Component Id="ApplicationShortcut" Guid="XXXXXXXXXXXXXXXXXXXXXXXXXXX">
    	  <Shortcut Id="ApplicationStartMenuShortcut" Name="MSD" Description="MSD" Target="[INSTALLFOLDER]MSD.exe" WorkingDirectory="INSTALLFOLDER" />
    	  <RemoveFolder Id="RemoveApplicationProgramsFolder" Directory="ApplicationProgramsFolder" On="uninstall" />
    	  <RegistryValue Root="HKCU" Key="Software\MSD" Name="installed" Type="integer" Value="1" KeyPath="yes" />
    	</Component>
      </DirectoryRef>
      <DirectoryRef Id="DesktopFolder">
       <Component Id="ApplicationShortcutDesktop" Guid="XXXXXXXXXXXXXXXXXXXXXXXXXXX">
    	 <Shortcut Id="ApplicationDesktopShortcut" Name="MSD" Description="MSD" Target="[INSTALLFOLDER]MSD.exe" WorkingDirectory="INSTALLFOLDER" />
    	  <RemoveFolder Id="RemoveDesktopFolder" Directory="DesktopFolder" On="uninstall" />
    	  <RegistryValue Root="HKCU" Key="Software\MSD" Name="installed" Type="integer" Value="1" KeyPath="yes" />
    	</Component>
      </DirectoryRef>
    </Fragment>
  27. Right-click SetupMSD in solution explorer.
  28. Select "Add" -> "Reference"
  29. Select WixUIExtension.dll
  30. Click "Add"
  31. Click "Ok"
  32. Now locate the line
    <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
  33. And add this below it
    <UIRef Id="WixUI_Minimal" />
  34. Locate the line
    <MediaTemplate />
  35. Replace it with
    <MediaTemplate EmbedCab="yes"/>
  36. Find the line that starts with
    <Product Id="*"
  37. Replace the asterisk "*" with a new unused GUID.
  38. Build with F6

References