DEV Community

Olabamiji Oyetubo
Olabamiji Oyetubo

Posted on

How to create an Installer for a Winforms application using Wix for Visual Studio 2022

In this tutorial, we’ll look at creating an installer for a Winforms desktop application using Wix that we can share with people.

The only prerequisite for this tutorial is Visual Studio Community edition, go ahead and download the installer here

After downloading, go ahead and install and open Visual Studio.

Next, we want to create a project, we will create a small Winforms application for this demo.

I have created a Winforms application in a previous post here, you can follow that link, create your application and then come back here.

When you're done configuring the project, go ahead and install the Wixv3 - Visual Studio 2022 extension we’ll use to setup our installer. In the Visual Studio top tab click Extensions and then click Manage Extensions
Search for installer projects, You will see Wix, click download

Install Wix

After downloading, Close your Visual Studio instance.

The VSIX installer comes up, go ahead and click modify.

After the modification is done and the extension is installed, go ahead and reopen your project again in Visual Studio. The extension should be added to your installed extensions.

We also need to install WiX Toolset v3.11.2, you can download the latest version from here

After downloading, simply run the installer and follow the prompts to install.

You might also be prompted to install .NET Framework 3.5, please follow the official Microsoft documentation on how to set that up here

Next, right-click on your project solution and add a new project.

In the Add project modal, we will see a list of new projects that have been installed. Search Wix

Add Wix project to solution

Give your project a name, I have called mine WixSetup, and click Create.

After successfully creating it, your solution should look like this.

Wix project file structure

Great, a new Xml file called Product.wxs was generated, this will hold all our logic. Let's go ahead and make some changes

First, change the Manufacturer in the Product element, I will change this to my name

<Product Id="*" Name="WixSetup" Language="1033" Version="" Manufacturer="Olabamiji" UpgradeCode="71fc5c9b-11ff-4b7c-b97a-320513ae22d4">
Enter fullscreen mode Exit fullscreen mode

Next in the 2nd Fragement element, let us configure what we want to add to our installer; so change your code so it looks like this

        <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
            <Component Id = "WixApp" Guid= "71fc5c9b-11ff-4b7c-b97a-320513ae22d4">
                <File Id = "WixApp" Name= "SetupInstallerTutorial.exe" Source= "..\SetupInstallerTutorial\bin\Debug\net8.0-windows\">
Enter fullscreen mode Exit fullscreen mode

Alright, We have made some changes, let's go through what we have added;
We added a Component and Specified an Id/Name for it. Then in that component we added a Guid, which acts as a unique identifier for that component, you can generate any guid you like.

Then inside the component element, we added a child node element called File, and gave it an Id that corresponds with our ComponentId. We also gave the file a name, which is the name of the .exe file that is generated when you build your winforms application. Finally, the source is simply where that winforms application .exe is created (bin folder of your project's directory)

Now in your solution explorer, right-click on the Wixsetup project and click build

Build Wix project

After building, Navigate to the bin folder of your Wix installer project.

Installer file location

We see that the installer has been generated and cab1 and Wixsetup.wixpdb files hold information about the files we add in our Product.wxs file.

And that’s it. Our installer for our application has been built, you can go ahead and run the WixSetup file to install your WinForms application.

Happy coding everyone.

Top comments (1)

scharde profile image

Happy to see some content regarding WIX.