OTHER RELATED ARTICLES:
- WPF - Visual Studio Integration and Designer Support in .NET Core 3.0
- Getting Started with DevExpress WPF Controls for .NET Core
- THIS POST: Migrate WPF Apps to .NET Core
- How to Deploy a .NET Core 3 App (coming soon)
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
- .NET Core 3 SDK
- Visual Studio 2019 version 16.3 (with the .NET desktop development workload installed)
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:
- Convert the application's project file (*.csproj or *.vbproj) to an SDK-style file (or create a new SDK-style project file).
- Upgrade the application's dependencies (NuGet packages) to the latest versions with .NET Core support.
- Change the target framework to .NET Core 3.
- Reference DevExpress controls using NuGet feeds instead of the Global Assembly Cache (GAC).
- 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
-
Video: Migrating a WPF App to .NET Core 3
A detailed walkthrough that covers WPF migration process.
-
Documentation: Port your code from .NET Framework to .NET Core
Microsoft's overview of the process and the tools you may find helpful when porting your code to .NET Core.
-
Blog: How to port desktop applications to .NET Core 3.0
A blog post that describes how to port both WPF and WinForms apps to .NET Core 3.
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.