Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Three Ways to Deploy a WinForms or WPF .NET Core Application

DZone 's Guide to

Three Ways to Deploy a WinForms or WPF .NET Core Application

Learn about three ways to deploy your .NET applications

· Web Dev Zone ·
Free Resource

This post will help you deploy and bring your finished app to your users. .NET Core 3 gives us three ways to deploy an app, and each has its benefits.

I know that the real fun is while an app is being developed, and we as developers are focused mainly on this part of creating an application. However, the real purpose of every app is to get to its end-users. 

To achieve it, deployment is a very important part of this process. In a previous post, I have talked about the benefits of .NET Core apps and how to convert an existing WinForms and WPF app to .NET Core.

Now, no matter whether the app is converted or completely new — it is time to continue with guidance on how to deploy it and bring the completed app to its users. .NET Core 3 gives us three ways to deploy an app and each has its benefits:

Framework-Dependent Deployment (FDD) and Framework-Dependent Executables (FDE)

These two approaches have one major thing in common — they depend on the installed  .NET Core outside the application. 

What Are the Benefits of These Two Approaches?

Benefits include a smaller size and the fact that multiple apps use the same .NET Core installation, which reduces both disk space and memory usage on host systems. 

What Are the Disadvantages?

As .NET Core is not part of the package, your app may not work or change its behavior based on the installed version of .NET Core on the host machine.

NOTE!  What are the main differences between FDD and FDE approach?
  • The first one outputs *.dll files, and the second outputs *.exe files.
  • The first can be used for multiple platforms; you don't have to define the target operating systems as your .NET Core app will run on in advance, while the second should be published separately for each target platform. 
  • With the FDE approach your app can be run by calling the published executable without invoking the dotnet utility directly. 

Now let's talk more about the third approach:

Self-Contained Deployment (SCD)

This is the new approach coming with .NET Core that opens up some great possibilities, and we will focus more on it in this post. With this approach, your app includes .NET Core inside it. SCDs include an executable (such as app.exe on Windows platforms for an application named app), which is a renamed version of the platform-specific .NET Core host, and a .dll file (such as app.dll), which is the actual application.   

What Are the Benefits?

You have control of the version of .NET Core that is deployed with your app. Other apps or updates cannot break the behavior of your app.  

What Are the Disadvantages?

  • You must select the target platforms for which you build deployment packages in advance.
  • The size of your deployment package is relatively large since you have to include .NET Core as well as your app and its third-party dependencies
    However with  .NET Core 3 Preview 6 it is possible to use Assembly Linker and significantly decrease the size of the app. 
    IL linker scans the IL of your application to detect which code is actually required and then trims unused framework libraries. This can significantly reduce the size of some apps. Just set  PublishTrimmed=true in your project. Typically, small tool-like console apps benefit the most, as they tend to use fairly small subsets of the framework and are usually more amenable to trimming. If your app uses reflection, be careful and read how to handle the case  here.

Now, as I said, we will focus on the third approach and take a deep dive into how we can use it. There are two ways to create deployment files for such an app — with the Command Prompt or with Visual Studio. 

As usual, I’ll use it to build an app for demo purposes. However, this time I’ll use the brand new .NET Core templates released with R2 2019 Release.  After you install Telerik components for WPF or WinForms, they will appear in your Visual Studio like this:

Template Telerik



VSX


With several clicks, I have prepared a functional desktop application for .NET Core — WPF Calendar app.

Calendar example

Now, let's deploy it.  

Deploying With Visual Studio

This is my preferred method for deployment. 

Note that there is difference in the approach depending on the version of Visual Studio. I’ll use the VS 2019 official version (version above 15.7) and describe the steps in details. However, if you're using an earlier version please refer to  this article from Microsoft.

Again, I want to remind you that with the SCD approach of deploying, we need to create a profile for every platform. So, you need to repeat the steps below for every platform you need to target.

Step 1. Right-click on the project (not the solution) in Solution Explorer and select Publish. 

Solution explorer


...and the "Pick a publish target" dialog box opens: 


Publish dialog


Step 2. Choose a deployment location.

Step 3. After that click on Configuration settings and choose self-contained deployment mode and choose target runtime.

Configure profile


Step 4. Save the configuration and run the Publish button. 

Now, let’s see what’s in the output folder:

Output


A bunch of dll files — all needed .NET Core assemblies and assemblies of your app including the Telerik ones.  

Note that there are some files in the location folder that are not mandatory for publishing, but I recommend to save them *.pdb. Save them to debug the deployed app if needed.

After we have the output files, you can deploy them in any way to the target machine — zip them, simply use the copy command or... with the new MSIX format.

What Is MSIX?

It is a new app packaging format for Windows applications that supports Win32, WPF, and WinForm apps

What Are the Benefits?

  • Works with any Win32, WPF, or WinForms apps (regardless of whether it is .NET Core 3).
  • Enables seamless distribution to the Microsoft Store.
  • Enables Side-Loading with Easy Download & Install Page.
  • Automatic App Updates.
  • Easily integrates with Continuous Integration.
  • Lights up some Windows 10 features like URI launching.

What Are the Disadvantages?

  • Only supports Windows 10 for "seamless install mode".
  • Requires special tools on Windows 7/8 (MSIX Installer).
  • Requires side-loaded app to be signed with cert (pretty standard, but not ideal for indie dev).
  • Sandboxes app like a UWP app.

To learn more about how to package the app, please refer to this post.

And now let's see an alternative way without using the studio.

Deploying With Command Prompt

Guess what? It is very easy. Just call dotnet publish --self-contained true  in your working directory and you are almost done. 

To configure the deployment use the following params:

-c Specify the Configuration.
-f 
Use for the framework.
-r 
Target Runtime Platform.

In my case the command will be: 

dotnet publish  -c Release -f netcoreapp3.0 -r win10-x64 --self-contained true 


More to Read

I hope you are as excited about all of the benefits of .NET Core 3 as we are! That is why we will love to hear more about whether you are going to convert your existing applications. Do you have any problems with that? Is there anything you would like the .NET Core version of Telerik UI for WPF and WinForms to include? Please share your feedback!

Let us know in the comments below or in our portals for WinForms and WPF.

In this post I tried to cover the base scenario; however for more details, you can refer to these Microsoft articles:

Happy deploying!

Topics:
web dev ,.net ,fdd ,scdl ,visual studio ,winform ,wpf

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}