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.
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
Let's say we want to convert a library called 'CoolControls'. Right-click on the
CoolControlsproject, and choose Unload Project.
Right-click again on
CoolControls, and choose Edit CoolControls.csproj.
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.csprojand paste them into
CoolControls.csproj, overwriting the old contents.
TempUnoproject from your solution.
CoolControls, then choose Reload Project.
In the Properties folder of
CoolControls, you'll need to remove the
AssemblyVersionand similar properties as those are now generated by msbuild using AssemblyInfo properties.
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 cross-targeted libraries article for how to add dependencies to your project.
Working with cross-targeted libraries
At present, there are a number of limitations related to Visual Studio when working with cross-targeted library projects. This article explains how to perform common operations when working with cross-targeted projects.
Adjusting code for Uno compatibility
See the next section for adjustments you may need to make to get your code compiling on Uno.