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 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:
These two approaches have one major thing in common - they depend on the installed .NET Core outside the application. This leads us to common advantages and disadvantages:
Benefits include a smaller size, and that multiple apps use the same .NET Core installation, which reduces both disk space and memory usage on host systems.
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, the second one *.exe files.
- The first one 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:
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.
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!
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 two ways to create deployment files for such an app – with the Command Prompt or with Visual Studio.
As usual, I’ll use Telerik Visual Studio templates 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:
With several clicks I have prepared a functional desktop application for .NET Core - WPF Calendar app.
Now, let's deploy it.
This is my preferred way! I <3 Visual Studio and its benefits.
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 remind you that with 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.
...and the "Pick a publish target" dialog box opens:
Step 2. Choose a deployment location.
Step 3. After that click on Configuration settings and choose self-contained deployment mode and choose target runtime.
Step 4. Save the configuration and run the Publish button.
Now, let’s see what’s in the output folder:
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 it *.pdb - save them to use it 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.
It is a new app packaging format for Windows applications that supports Win32, WPF, and WinForm apps
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.
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
I hope you are as excited about all of the benefits of .NET Core 3 as we - the people working on Telerik UI components - 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!
In this post I tried to cover the base scenario, however for more details you can refer to these Microsoft articles:
Rossitza Fakalieva is Manager of the Progress .NET UI & Tools division, which develops the UI for WPF, UI for WinForms, UI for UWP and UI for Xamarin products. She started her career on the Telerik ASP.NET team in 2006 as a support officer and passed through the position of software developer to the position of senior manager. Off work, she enjoys cooking, watching movies and reading books.
Subscribe to be the first to get our expert-written articles and tutorials for developers!