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
To use WixSharp, open the Visual Studio 2022 - Extensions menu => Manage Extensions window, search for wixsharp, and install the WixSharp Project Templates.
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.
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.
ยฉ 2025 juniyunapapa@gmail.com.