Creating a simple setup

WiX Toolset

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 Setup 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. Find the comment that says:

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

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

    <File Source="$(var.MyApplication.TargetPath)" />
    
  7. Build the WiX project.

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

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.

The line of code you added instructs the WiX toolset to add a file resource to the setup package. 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.