WinForms - Single-File Applications With .NET Core 3

WinForms Team Blog
20 May 2019

Shortly after Microsoft announced WinForms support for .NET Core 3, we published a blog post to confirm our commitment to .NET Core. Recently Microsoft posted about .NET Core 3 Preview 5 and their long-term plans. An interesting .NET Core feature is the support for single-file executable AOT-compiled apps. Read on to find out how to use this functionality with one of the DevExpress WinForms demos for .NET Core 3.

Prerequisites

First, you need to install the .NET Core 3 Preview 5 SDK. For the purposes of this article, the SDK is all you need – for your own projects, the latest Visual Studio 2019 should also be available.

Clone the GitHub repository DevExpress .NET Core WinForms Demos on your machine, using Git command line tools or Visual Studio, or by downloading a zip file.

Note that the file README.md in the repository contains instructions to work with the demos in Visual Studio. However, this is not required to see the single-file executable publication mechanism in action.

Test Single-File Executable Publication

Open a command prompt and use the cd command to navigate to the StockMarketTraderApp demo folder. Run the command dotnet publish -r win10-x64 to build and publish the solution.

The parameter -r win10-x64 identifies the target platform for the application. See the article .NET Core RID Catalog for more information.

For most real-world scenarios you should add the parameter -c Release to build the application using the Release configuration. Otherwise, it will be built using Debug.

In the demo folder, navigate to the newly created directory \bin\Debug\netcoreapp3.0\win10-x64\publish (or \bin\Release\netcoreapp3.0\win10-x64\publish if you added -c Release) The folder contains more than 340 files that you need to distribute to your end-users, including assemblies for your own application logic, standard .NET and DevExpress assemblies. Building for the Release configuration produces fewer files, but the difference is not large.

Standard Publication Folder

Run DevExpress.StockMarketTrader.exe and check the memory consumption in the task manager. On our test machine the value varied between 220 and 260 MBytes.

Memory Consumption for Multi-File Executable

To test single-file executable publication, delete the folder bin. Now run the dotnet publish command again, but this time add a parameter to set the PublishSingleFile property for MSBuild:

dotnet publish -r win10-x64 -c Release -p:PublishSingleFile=true

Check the auto-generated publish folder again, in the same path as before. This time you’ll see a single file, a 267-megabyte self-extracting executable.

Single-File Publication Folder

This file runs the StockMarketTrader demo on any Windows 10 x64 bit machine and contains everything the application needs in one file.

The Running Application

The first application launch takes a bit longer than for a multi-file deployment, since all dependencies are unpacked into a temporary folder in %AppData%.

Temporary AppData Folder

On further runs, there are no penalties on startup time or memory consumption.

Memory Consumption for Single-File Executable

More Information

Microsoft promises that by the time of the .NET 5 release you will be able to publish single-file executables created by the ahead-of-time (AOT) compiler, as an alternative to the self-extracting executables available now. We are watching all .NET Core updates closely to make sure our controls and components fully support all new features.

Several design documents are available about single-file publication. If you’re curious, please check out these links:

DevExpress Winforms For .NET Core 3

DevExpress NuGet packages are available to use our WinForms components with .NET Core 3. We recently updated these packages with support for additional assemblies, and everything is now built natively with .NET Core 3.

Here is the demo link again. The paragraph Integrate DevExpress WinForms Controls into a .NET Core 3 application of the Readme has instructions for the early-access NuGet feed.

10 comment(s)
Jon Davis
Jon Davis

What about ILMeege? I haven't used ILMerge in years, never in .Net Core, but I'd assume this should work without self-extraction.

20 May, 2019
Jon Davis
Jon Davis

Re prev comment: ILMerge not ILMeege

20 May, 2019
Customer81473
Customer81473

Dotnet Warp is an option nowadays github.com/.../dotnet-warp

20 May, 2019
Dmitry Babich (DevExpress)
Dmitry Babich (DevExpress)

@Jon

We were informed about various issues when using ILMerge. For example, take a look at this ticket:

T440157

21 May, 2019
Steve Sharkey
Steve Sharkey

Whole applications in a single executable... It's like a trip down memory lane!

21 May, 2019
Chris Royle (LOB)
Chris Royle (LOB)

And then the .exe is large file so you can use something like ASPack to compress it :D

21 May, 2019
Antonio Matos 1
Antonio Matos 1
Could we migrate existing WinForms app to .NET Core ?
2 August, 2019
Svetlana (DevExpress Support)
Svetlana (DevExpress Support)

@Antonio Matos 1

To learn how to port your app to .NET Framework to .NET Core, follow the tips from the Port your code from .NET Framework to .NET Core Microsoft topic. 

After that, download .NET Core assemblies for our components by using NuGet as we described in the Trial .NET Core controls via NuGet topic. If you have more questions regarding the support of .NET Core support for our controls, feel free to submit a ticket to our Support Center. 

5 August, 2019
Customer95314
Customer95314
Hello, I use -p:PublishSingleFile=true parameter to publish a .Net Core 3 Winform app. It did create one .exe file and .pdb file. However, it would not produce my config file. And when I put my config file in the same publish folder, the contents of the config file gets ignored.  For example, if I have a key-value pair of  CheckIntervalInMinutes , when I change the interval it did not take effect. I even displayed it on the UI and it would not display what's in the config file. Could you please help me out and see what I'm missing? Thank you!
21 August, 2019
Customer95314
Customer95314
Please ignore that question. Yes App.config is ignored in Winform Core if we use Configurationmanager. However, if we build a class that inherits ConfigurationProvider then we could read the xml, parse it, and populate our custom Dictionary<string, string>, in which any changes in App.config will be reflected in.
21 August, 2019

Please login or register to post comments.