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.

Free DevExpress Products - Get Your Copy Today

The following free DevExpress product offers remain available. Should you have any questions about the free offers below, please submit a ticket via the DevExpress Support Center at your convenience. We'll be happy to follow-up.
No Comments

Please login or register to post comments.