๐Ÿ˜œ

์ญˆ๋‚˜์•„๋น  ๋ธ”๋กœ๊ทธ

JUNA
STUDIO

[C#][.NET] Creating an MSI Installer with WixSharp

๋ฐœํ–‰์ผ: Feb, 2025
์กฐํšŒ์ˆ˜: 3
๋‹จ์–ด์ˆ˜: 385

Table of Contents

1. Introduction to WixSharp

If you have ever created an installation file for deploying Windows Desktop applications, you might have used the Wix toolset at least once. It is a powerful tool provided for free as open-source, but it has the inconvenience of having to write XML tags one by one. Especially for customizing the installation dialog, you need to specify the coordinates of each control one by one, and to verify it, you have to create the msi file and run it, which is quite inconvenient.

WixSharp is a great tool that allows you to write these inconvenient XML tags in C# code. In particular, it is very convenient because you can implement the harvest of the installation target files simply using C# Linq without having to learn how to use the heat command and filter methods separately, and you can customize the WPF view directly on the designer screen.

Github: https://github.com/oleg-shilo/wixsharp


2. Installing WixSharp VS Extension

To use WixSharp, open the Visual Studio 2022 - Extensions menu => Manage Extensions window, search for wixsharp, and install the WixSharp Project Templates.


3. Creating a WixSharp Project

First, create a solution named WixSharpTest and a console application project named MyApp.

Right-click on the solution and add a new project. Search for WixSharp, and several project templates will appear. Select Custom WPF UI.

Name the project MyAppInstaller.

Since the template references older versions of NuGet packages, update them to the latest versions.


4. Building the Target Project and Installer Project

 Modify the Program.cs file of the MyAppInstaller project as follows.

using System;
    using System.Windows.Forms;
    using WixSharp;
    using WixSharp.UI.WPF;
    
    namespace MyAppInstaller
    {
        internal class Program
        {
            static void Main()
            {
                var productName = "MyApp";
                var companyName = "HiperzStudio";
    
                var project = new ManagedProject($"{productName}",
                                  new Dir($@"%ProgramFiles%\{companyName}\{productName}",
                                      new Files("*.*")));
    
                project.GUID = new Guid("6fe30b47-2577-43ad-9095-1861ba25889b");
    
                // project.ManagedUI = ManagedUI.DefaultWpf; // all stock UI dialogs
    
                //custom set of UI WPF dialogs
                project.ManagedUI = new ManagedUI();
    
                project.ManagedUI.InstallDialogs.Add<MyAppInstaller.WelcomeDialog>()
                                                .Add<MyAppInstaller.LicenceDialog>()
                                                .Add<MyAppInstaller.FeaturesDialog>()
                                                .Add<MyAppInstaller.InstallDirDialog>()
                                                .Add<MyAppInstaller.ProgressDialog>()
                                                .Add<MyAppInstaller.ExitDialog>();
    
                project.ManagedUI.ModifyDialogs.Add<MyAppInstaller.MaintenanceTypeDialog>()
                                               .Add<MyAppInstaller.FeaturesDialog>()
                                               .Add<MyAppInstaller.ProgressDialog>()
                                               .Add<MyAppInstaller.ExitDialog>();
    
                // Location of the application's binary files to be deployed
                project.SourceBaseDir = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), @"..\MyApp\bin\debug\net6.0");

                // Folder to create MSI
                project.OutDir = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), @"bin\deployment");
    
                project.BuildMsi();
            }
        }
    }

Now, if you build MyApp and then build MyAppInstaller, an msi file will be created in the bin\deployment folder.


When you run MyApp.msi, you will see the installation GUI as shown below. It's very simple, right?

Now, if you proceed with the installation, you can see that it is installed correctly under the Program Files folder as shown below.

You can also see that MyApp appears in the list in the Windows Add or Remove Programs console as shown below.

In the next post, we will learn how to filter the target files for deployment and create shortcut icons on the desktop and start menu.

Tags: #WixSharp#Wix toolset#Windows Desktop applications#installation file#Visual Studio#project template#NuGet packages#WPF view#C##tutorial
JUNA BLOG VISITORS
Today
1
 (
updown
-6
)
Total
62
 (
updown
+1
)

ยฉ 2025 juniyunapapa@gmail.com.