Migrate WPF Apps to .NET Core

WPF Team Blog
29 October 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. THIS POST: Migrate WPF Apps to .NET Core
  4. How to Deploy a .NET Core WPF App

This blog post details how you can upgrade an existing WPF application to .NET Core 3 (and enjoy Microsoft’s new technology enhancements with as little pain as possible).

Before You Start

Prerequisites

Limitations and Portability

Your application may use certain APIs that are missing in .NET Core 3. To determine if you’re using such APIs, please use the .NET Portability Analyzer tool.

Note: You should try to refactor application code and reduce the number of missing APIs calls. You may be able to find an alternative API with the desired functionality.

Update NuGet Packages

Check whether the NuGet packages used within your project are compatible with .NET Core 3 and whether newer (compatible) versions are available.

If your project uses old package versions, please update your project accordingly. Perform this step even if Visual Studio does not display compile-time errors. You may experience runtime exceptions if you build an application with packages that were not tested against .NET Core 3 runtime

Migrate Your Application

The Process

Migrating a WPF application from .NET Framework to .NET Core requires the following steps:

  1. Convert the application's project file (*.csproj or *.vbproj) to an SDK-style file (or create a new SDK-style project file).
  2. Upgrade the application's dependencies (NuGet packages) to the latest versions with .NET Core support.
  3. Change the target framework to .NET Core 3.
  4. Reference DevExpress controls using NuGet feeds instead of the Global Assembly Cache (GAC).
  5. Review/fix errors and exceptions that appear at both compile and run time.

Important: You should backup your project before migration.

Create a New Project File

.NET Core only works with the new SDK-style project file format.

Use the code sample below as a template to create a new *.csproj (*.vbproj) file.

<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
 
	<PropertyGroup>
	  <OutputType>WinExe</OutputType>
	  <TargetFramework>netcoreapp3.0</TargetFramework>
	  <UseWPF>true</UseWPF>
	  <UseWindowsForms>true</UseWindowsForms>
	</PropertyGroup>
   
  </Project>


Replace your existing project file with the newly generated SDK-style project file.

Switch DevExpress References from GAC to NuGet

Add DevExpress NuGet packages:

1. Register a local or online DevExpress NuGet Feed.

2. Find and install the DevExpress.WindowsDesktop.Wpf and DevExpress.WindowsDesktop.Wpf.Themes.All packages.

Once you have added these packages to your project, Visual Studio will load and display DevExpress WPF controls within its Toolbox.

Your project is now ready to run on .NET Core 3. All you need to do is to fix/address possible issues.

Fix Build Issues

Refactor your code so that it builds and runs successfully on the newest NuGet package versions and .NET Core API.

Useful tips:

1. Use the Microsoft.Windows.Compatibility package. It adds windows-specific APIs: Registry, WCF Client, ACL, etc.

2. Use conditional compilation to write code that differs between .NET Core and .NET Framework.

Before you proceed, we recommend that you review the following online document: .NET Framework technologies unavailable on .NET Core.

Useful Resources

We'd Love to Hear from You

If .NET Core 3 is an important part of your development strategy, we’d love to hear from you. Please comment below or email us at wpfteam@devexpress.com to share your plans and long-term needs.

18 comment(s)
Tobias Johansson
Tobias Johansson
When will the visual studio report designer for WPF .net core be ready?
29 October, 2019
Krzychu
Krzychu
how about trial version?
30 October, 2019
Alex Chuev (DevExpress)
Alex Chuev (DevExpress)

Krzychu,

Feel free to download a trial version of our .NET Core 3.0 installer here:
https://www.devexpress.com/Products/Try/
If you prefer working with online NuGet packages, obtain your trial NuGet feel URL here:
https://nuget.devexpress.com/

30 October, 2019
DANIEL SASS
DANIEL SASS
Does the .NET Core versions support app.config settings? I did this a few days ago with one of my smaller apps. I was originally using a DXThemeManager setting in my App.config to set the theme, but that seemed to stop working when I migrated to .NET Core 
30 October, 2019
Dmitry Tok (DevExpress Support)
Dmitry Tok (DevExpress Support)

Hello Tobias,

Visual Studio's integrated Report Designer in desktop platforms (WinForms and WPF) is based on the standard WinForms designer. Since the new WinForms designer for .NET Core 3 is not yet fully available, the best way to design your reports is to use the workaround with linked *.cs and *.Designer.cs files. See Reporting in .NET Core 3 (CTP) help topic for further information. 

30 October, 2019
Alex Chuev (DevExpress)
Alex Chuev (DevExpress)

Daniel,


It will be necessary to call the ApplicationThemeHelper.UpdateApplicationThemeName method to load a theme name from the App.config file. I've created a Support Center ticket where we can discuss the details:
https://supportcenter.devexpress.com/ticket/details/t828145/applying-a-theme-from-the-app-config-file-in-net-core-3 

30 October, 2019
Mark Holt
Mark Holt

I'm getting a warning when I add a reference to the DevExpress.Mvvm package:


Warning NU1701

Package 'DevExpress.Mvvm 19.2.3' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETCoreApp,Version=v3.0'. This package may not be fully compatible with your project.



1 November, 2019
Krzychu
Krzychu
I installed the Core pack (Winforms+Reporting). Then I created new netcore3 WinForms app, referenced DevExpress.WindowsDesktop.Core but I can't do anything, cant see classes like XtraForm, GridControl etc, tried to build a form in code. Whan am I doing wrong? or maybe only WPF is included atm?
 
2 November, 2019
Andrew Tinkler
Andrew Tinkler
Hey Lex, Thanks for this useful article. We will be starting our migration next year.
3 November, 2019
Hans Nieuwenhuis
Hans Nieuwenhuis

I have the same warning as Mark Holt about DevExpress.Mvvm in my .NET Core 3 library.

I used the 'automatic' way of adding the MVVM package. The way given as option in Visual Studio 2019. I could not find an MVVM package in the DevExpress NuGet feed.

4 November, 2019
Hans Nieuwenhuis
Hans Nieuwenhuis
correction: it's not in my .NET Core 3 library, but in a .NET Core 3 NUnit test project.
4 November, 2019
Alex Chuev (DevExpress)
Alex Chuev (DevExpress)

@Krzychu:

For WinForms development, you will need to install the DevExpress.WindowsDesktop.Win package. Please take a look at the following article to learn more:
WinForms Documentation - .NET Core 3.0 Support


@Mark and Hans:

The DevExpress MVVM framework for .NET Core 3.0 comes as a part of other NuGet packages (DevExpress.WindowsDesktop.Wpf and DevExpress.WindowsDesktop.Win). You can also install a free version of the MVVM framework from the official NuGet feed:

https://www.nuget.org/packages/DevExpressMvvm/

We are going to add a separate DevExpress.WindowsDesktop.Mvvm package to the DevExpress NuGet feed in the context of the following ticket:
T830006 - The DevExpress MVVM Framework for .NET Core 3.0 is not available as a separate NuGet package

5 November, 2019
Krzychu
Krzychu
I was missing Include prerelease in order to install DevExpress.WindowsDesktop.Win. Now its working.
6 November, 2019
Hans Nieuwenhuis
Hans Nieuwenhuis

I assume the DevExpress MVVM framework can also be used in ASP.NET (Core) applications. If yes, then I think it's strange that that package is now part of DevExpress.WindowsDesktop.Wpf.

For the same reason, I also think DevExpress.WindowsDesktop.Mvvm is not a correct name, because I think it can also be used on a Windows Server. And maybe even on Linux/MacOS, but that I don't know.


6 November, 2019
Hans Nieuwenhuis
Hans Nieuwenhuis

If I try to build my .NET Core 3 NUnit test project with NuGet package DevExpress.WindowsDesktop.Wpf (because I need MVVM), I now get the following error message:


Microsoft.NET.Sdk.WindowsDesktop is required to build Windows desktop applications. 'UseWpf' and 'UseWindowsForms' are not supported by the current SDK.


 

7 November, 2019
Alex Chuev (DevExpress)
Alex Chuev (DevExpress)

Hans,


Let's discuss your requirement with the MVVM framework in the following Support Center ticket:
How to use the DevExpress MVVM framework for .NET Core in non-desktop projects

7 November, 2019
Blago Culjak
Blago Culjak
Can someone explain to me what are the benefits of migrating to WPF to Core?
8 November, 2019
Alex Chuev (DevExpress)
Alex Chuev (DevExpress)

Blago,


Julian sums this up nicely in his blog post: .NET Core 3.0 Support for ASP.NET Core, WinForms, and WPF Controls.
In short, .NET Core 3.0 provides WPF developers with new deployment options, native images compiled in advance, and quite possibly more new features in the future. .NET Framework is not going to be deprecated any time soon, but will only receive maintenance updates and security fixes. Microsoft recommends choosing .NET Core for new projects, but whether to migrate existing ones is up to you.

11 November, 2019

Please login or register to post comments.