How to convert class library that is targeted WPF to .NET Core 3.0 from .NET Framework
At Connect(); 2018, .NET Core 3.0 Preview 1 was released and to support WPF/WinForms announced.
I’ve been owned two libraries that are ReactiveProperty and Livet. ReactiveProperty is targeted .NET Standard 2.0. .NET Standard 2.0 is available for .NET Core. However, Livet is targeted .NET Framework 4.5.2 or later. So, I have to convert it when I’ll use it on .NET Core 3.0. This article is working logs that I did.
Create a .NET Core 3.0 class library project that name is Livet.NetCore.
The project file that is generated is as below:
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>netcoreapp3.0</TargetFramework> </PropertyGroup> </Project>
I changed the project file in order to support WPF. Changed the “Sdk” attribute at Project tag to Microsoft.NET.Sdk.WindowsDesktop, and then added “<UseWPF>true</UseWPF>” to under the PropertyGroup tag.
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop"> <PropertyGroup> <TargetFramework>netcoreapp3.0</TargetFramework> <UseWPF>true</UseWPF> </PropertyGroup> </Project>
After that, under the dependencies node of the project would change like below:
At Livet project, all of codes are in Shared project. So, I added reference to it on the Livet.NetCore project. If in your product there is no shared project, then at first you create a shared project, and then copy all code to there.
After that, a lot of errors occurred.
The errors were by to depend the behavior feature. I had to add a reference that is “System.Windows.Interactivity.WPF” manually, using NuGet package manager.
All compile errors was fixed! However, the package is targeted .NET Framework 4.6.1. Below warning occurred.
At “C:\Users\User name\.nuget\packages\system.windows.interactivity.wpf\2.0.20525\lib\net40”, I checked compatibility using Microsoft API Portability Analyzer with below command:
path to apiport.exe folder\ApiPort.exe analyze -f .
The detail of ApiPort.exe is written on previous article.
On the report that is result of the command, there is green at .NET Core column.
I decided ignoring the warning. I added “NU1701” to NoWarn item of Properties window of System.Windows.Interactivity.WPF in order to ignore the warning.
Publish to NuGet
Final step is that publish to NuGet. It is very easy. Fill information to Package tab of project properties.
And then, select publish menu of project’s context menu.
After completed the wizard, would be generated a nupkg file. then upload to nuget.org.
I converted the class library that is targeted .NET Framework to .NET Core 3.0. In this class library, it was very easy, however if your product depends Windows specific features(ex: XBAP, Windows service, COM, etc…), then I think you will have to need additional steps.