How to deploy .NET WPF applications using MSI installer

Written by Renato Ivanescu · April 12th, 2023

Windows Presentation Foundation (WPF) is a powerful User Interface (UI) framework for building desktop client apps. It's a part of .NET and offers a multitude of helpful features, such as media services, controls, data binding, and security.

The WPF framework platform allows you to develop applications efficiently, since it separates the application behavior from its UI. For example, you can use XAML markup for developing the front-end of the application and a programming language for the back-end.

By separating an app's behavior from its user interface, its development and maintenance become easier.

In this article, we’ll show you how to create an MSI for a .NET WPF application using Visual Studio (VS).

How to Create a WPF Application in Visual Studio

Before creating the MSI installer, we’ll need a WPF application. In case you don’t have one already, follow these steps to create one in Visual Studio:

1. Go to FileNew Project.

2. Set language to C#, platform to Windows and project type to Desktop.

3. Select WPF Application from the template list.

WPF Application Template in Visual Studio

4. Name it in the Configure your new project windows (e.g. MyApp).

5. Next, make sure to specify the version of .NET that your application targets. Depending on the versions installed on your computer, this option can have different values. For this example, we selected .NET 6.0.

6. After you choose the version, press the Create button to create the WPF application.

The Version of .NET your WPF Application Targets

How to Add a Setup Project to Your WPF Application

Before we create our MSI installer, we first need to download the Microsoft Visual Studio Installer Project extension.

Let’s see how to add the extension to Visual Studio:

1. Go to ExtensionsManage extensions.

2. In the left menu, select OnlineVisual Studio Marketplace.

3. Search for Microsoft Visual Studio Installer Project in the list of extensions.

4. Select the extension and press the Download button. Be aware that the extension will be installed only after you close Visual Studio.

Microsoft Visual Studio Installer Project Extension

Once the extension is installed, we can create the Setup project for our application.

1. Right-click on the project solution → AddNew Project.

2. From the Add new project window, choose Setup project and then name it. In our example, its name is AppSetup.

Create Setup Project in Visual Studio

After creating the Setup project, you should see it in the Solution Explorer.

Setup Project in the Solution Explorer Menu in Visual Studio

How to Add Project Output to Your WPF Setup Project

Now, we need to specify the project we're creating the installer for, which is MyApp. For this, right click on AppSetupAddProject output.

Add Project Output to WPF Setup Project in Visual Studio

From the opened dialog, choose your project and then select Publish Items which contains all the assemblies needed when publishing a .NET project.

Select Publish Items in Add Project Output Groups

How to Create a Desktop Shortcut for Your WPF Application

To create a Desktop shortcut for your WPF application, follow the next steps:

1. Right click on AppSetupViewFile System.

View File System of WPF Setup Project in Visual Studio

2. Under the File System open the Application Folder. Next, right-click on Publish Items from MyApp and select Create Shortcut to Publish Items from MyApp.

Create Shortcut to Publish Items for WPF Setup Project

3. Rename the shortcut and place it in the User's Desktop folder.

WPF Setup Project Shortcut placed in User;s Desktop Folder

Build and Install Your WPF Application

You’ll first need to build the MyApp, followed by the AppSetup. After you build the AppSetup for the first time, a launch condition regarding dependency on .NET is automatically generated.

This launch condition checks if the destination computer has the same .NET Desktop Runtime version that the application targets. You can keep the default launch condition properties or change them if needed.

To access the launch condition, right click on AppSetup View Launch conditions.

Access the .NET Core Launch Condition

If you want to change the launch condition properties, select the condition and then go to the Properties section.

Launch Condition Properties in Visual Studio

For example, we made the following changes:

- We set the runtime from Auto to Windows Desktop,

- Added 6.0.7 to the version and,

- We set the architecture to x64.

Thus, the installer will require the x64 .NET Desktop Runtime version 6.0.7 in order to run.

Installer Requires the x64 .NET Desktop Runtime version 6.0.7

If you press Yes, you’ll be redirected to dotnetmicrosoft.com to download the specific .NET Desktop Runtime.

If you have the runtime version that the application targets, you only have to go through the classic installation process.

Conclusions

Visual Studio enables you to create installer packages for WPF applications, regardless of the .NET version. For basic WPF applications, Visual Studio is a reliable solution. However, it does have some limitations when it comes to complex packaging scenarios.

We highly recommend using a tool such as Advanced Installer, which offers reliable customization options, a user-friendly GUI, and support for multiple platforms.

To see just how simple it is to create and manage MSI packages in Advanced Installer, check out the following tutorial.

Written by
See author's page
Renato Ivanescu

Renato is a technical writer for Advanced Installer and an assistant professor at the University of Craiova. He is currently a PhD. student, and computers and information technology are his areas of interest. He loves innovation and takes on big challenges.

Comments: