Migrating a WinUI or UWP class library to an Uno Platform class library
This article describes how to port a class library for UWP to one that supports multiple target platforms using Uno.
It assumes you're using Visual Studio for Windows, but the steps are similar if you're using VS Code or another IDE.
Prerequisites
Follow the instructions to set up your development environment for Uno Platform.
Applying Uno Platform project structure
Adding Uno Platform support to an existing class library entails changing the contents of the existing .csproj
file. The easiest way to do that is to create a temporary Uno class library and copy its contents into the existing .csproj
file. The steps in detail:
Open the solution containing the WinUI/UWP-only library you wish to convert.
Create an Uno Platform Library project in the same solution, and name it
TempUno
.Let's say we want to convert a library called 'CoolControls'. Right-click on the
CoolControls
project, and choose Unload Project.Right-click again on
CoolControls
, and choose Edit CoolControls.csproj.Right-click on
TempUno
, then Edit TempUno.csproj. (There is no need to unload this type of project)Make a temporary copy of the contents of
CoolControls.csproj
(eg in a Notepad window) - you will refer to this when restoring dependencies.Copy the entire contents of
TempUno.csproj
and paste them intoCoolControls.csproj
, overwriting the old contents.Delete the
TempUno
project from your solution.Right-click on
CoolControls
, then choose Reload Project.In the Properties folder of
CoolControls
, you'll need to remove theAssemblyVersion
and similar properties as those are now generated by msbuild using AssemblyInfo properties.
Adding dependencies
If your class library had additional dependencies, you will need to restore them. See here for tips on finding compatible dependency versions for each target. See the working with Control libraries article for how to add dependencies to your project.
Adjusting code for Uno compatibility
See the next section for adjustments you may need to make to get your code compiling on Uno.