How to Deploy a .NET Core WPF App

WPF Team Blog
11 November 2019

OTHER RELATED ARTICLES:

  1. WPF - Visual Studio Integration and Designer Support in .NET Core 3.0
  2. Getting Started with DevExpress WPF Controls for .NET Core
  3. Migrate WPF Apps to .NET Core
  4. THIS POST: How to Deploy a .NET Core 3 WPF App

In this blog post, we'll describe how you can publish an application using Visual Studio tools.

The Process

.NET Core 3 allows you to publish WPF applications in the following ways:

  • Framework-Dependent Executable

    In this mode, your application is published with its dependencies. The .NET Core runtime is not included. The deployed application is dependent upon the .NET Core runtime installed on the target machine.

    Use this approach if you wish to deploy your application to workstations with the .NET Core 3 runtime already installed.

  • Self-Contained Deployment

    In this mode, your application does not depend on the .NET Core runtime installed on the target machine. .NET Core runtime and all application dependencies are included into the distribution.

Publish in Visual Studio

To publish an application, right-click the project file and select Publish.

At the first run, create a new publish profile:

Click Edit Configuration:

In the Profile Settings window, select the required Deployment Mode and click Save:

Click Publish to publish your app to the specified folder.

Publish via the Command Line

# <RID> - Runtime Identifier: win-x86, win-x64, etc.
# Framework-dependent executable:
dotnet publish -c Release

# Self-contained deployment:
dotnet publish -c Release -r <RID> --self-contained true

Deployment Options

Single Executable

You can pack your application and all its dependencies (including .NET Core 3 runtime) into a single executable.

To do this, add the following options to your project file:

<PropertyGroup>
  <RuntimeIdentifier>win10-x64</RuntimeIdentifier>
  <PublishSingleFile>true</PublishSingleFile>
</PropertyGroup>

Once you publish the app, you'll see a single executable and a *.pdb for debugging.

Ready to Run Images

Many .NET Framework developers use Ngen.exe to reduce application launch time.

Ngen.exe does not work for .NET Core. But .NET Core 3 allows you to speed up application startup time by compiling your application in a ReadyToRun (R2R) format.

R2R binaries contain native code (similar to what the just-in-time (JIT) compiler produces). This native code reduces the JIT compiler workload during application startup.

To publish an app in the R2R format, set the <PublishReadyToRun> option to true in your project file:

<PropertyGroup>
  <PublishReadyToRun>true</PublishReadyToRun>
</PropertyGroup>

R2R binaries are larger because they contain both native and IL code.

R2R format is only available for self-contained apps that target specific runtime environments (RID) - such as Windows x86 or Windows x64.

We'd Love to Hear From You

We want to hear from those of you targeting .NET Core 3. Please tell us how you plan on porting your existing projects and how we can better serve your needs during the conversion process.  Feel free to comment below or email us at wpfteam@devexpress.com.

5 comment(s)
Customer101928
Customer101928
What about MSIX?
12 November, 2019
Lex (DevExpress)
Lex (DevExpress)
MSIX is a very broad topic to include in this post. We can write an article about it in the future - thanks for the idea.

In the meantime, if you are interested in MSIX packaging, check out these resources:
13 November, 2019
Stephen J White
Stephen J White

@Lex I'd definitely appreciate if you could cover MSIX in the future. Microsoft hasn't really provided a decent explanation on how to get PublishSingleFile and Trim to work with MSIX/Desktop Bridge. I've tried suggestions from other places, but it seems like the MSIX always end up containing loose files. It's not a big deal since the MSIX is already compressed, but it would be nice to have it be smaller to reduce download size.

I probably should also point out that both of those links don't really specify one of the obscure limitations of MSIX right now - if you are using the feature in Windows 10 to automatically check for updates, Windows does not run the updater if you launch an app using MSIX via a traditional shortcut file (I.E. desktop shortcut, taskbar icon). If anyone is curious about working around this, I posted a quick and dirty example using the Windows 10 SDK/API over at Stack Overflow: https://stackoverflow.com/questions/58345859/net-core-wpf-desktop-bridge-desktop-shortcuts-task-bar-shortcuts-bypasses-c 

18 November, 2019
Lex (DevExpress)
Lex (DevExpress)

Hi Stephen!

Thank you for sharing your experience on MSIX limitations.

As for the `PublishTrimmed` option, note that trimming WPF apps can be tricky - see the IL Linker documentation page: https://github.com/mono/linker/tree/master/src/ILLink.Tasks#adding-reflection-roots

19 November, 2019
Stephen J White
Stephen J White

@Lex

Thanks for the link, that's pretty interesting. I wasn't aware of how tricky it could be to get things to work. But that's probably one of the interesting things about WPF that makes me love it (the little details).

Anyways, I ended up asking around and Tanka Jimha was kind enough to answer that publish single file isn't supported currently with MSIX/App Installer projects:


https://techcommunity.microsoft.com/t5/MSIX-Packaging-and-Tools/Is-It-Possible-To-Use-Publish-Single-File-In-Net-Core-3-With/m-p/1040085#M527


Hopefully this is something you can point out in your next blog post. 


29 November, 2019

Please login or register to post comments.