Creating a simple setup

Windows Installer XML

Creating a Simple Setup

In this tutorial, we will create a C# Windows Form Application and then use WiX to create an installer for the application.

Step 1: Create the C# Windows Form Application

  1. Click File, then select New, then select Project.
  2. Choose the Visual C# node in the Project Types tree, then select Windows Forms Application.
  3. Name your application "MyApplication" and press OK.

Step 2: Create the installer for the application

  1. Click File, then click New, then click Project.
  2. Choose the Windows Installer XML node in the Project types tree, then select WiX Project
  3. Name your project "MySetup" and press OK.
  4. In the MySetup project, right-click on the References node and choose Add Reference....
  5. Navigate to the Projects tab, click on the MyApplication project, and click the Add button, and then press OK.
  6. Build the WiX project.

That's it! Now you have a working installer that installs and uninstalls the application.

Note: After step 5, the appropriate WiX authoring is auto-generated to reference the application project. To disable auto-generation, right-click on the MyApplication project reference and go to Properties, then set the Harvest property to False. To manually add the project reference into the WiX source file, open MySetup.wxs and you will see a comment that says:

    <!-- TODO: Insert your files, registry keys, and other resources here. -->

Delete this line and replace it with the following lines of code:

    <File Id="MyApplicationFile" Name="$(var.MyApplication.TargetFileName)" Source="$(var.MyApplication.TargetPath)"
          DiskId="1" KeyPath="yes" />
    

If you type that code into the editor (instead of copying and pasting from this example) you will notice that IntelliSense picks up the valid elements and attributes. IntelliSense with WiX in Visual Studio can save you significant amounts of typing and time when searching for the name of the elements or attributes as you become more comfortable with the WiX language.

That line of code instructs the WiX toolset to add a file resource to the setup package using "MyApplicationFile" as its package identifier. The Name attribute specifies the name for your file when it is installed and the Source attribute specifies where to find the file for packaging during the build. Rather than hard-code values for these attributes into our source code, we use the WiX preprocessor variables that are passed to the WiX compiler. More information about using preprocessor variables, including a table of all supported values, can be found in the Adding Project References topic.

The DiskId attribute instructs the WiX toolset to add this file to the Media element with matching Id attribute. In this example, the MyApplication executable is added to the MySetup.cab cabinet and that cabinet is embedded in the setup package. The KeyPath attribute instructs the WiX toolset to use this file as the key path for the component that contains the file.