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:

  1. Open the solution containing the WinUI/UWP-only library you wish to convert.

  2. Create an Uno Platform Library project in the same solution, and name it TempUno.

  3. Let's say we want to convert a library called 'CoolControls'. Right-click on the CoolControls project, and choose Unload Project.

  4. Right-click again on CoolControls, and choose Edit CoolControls.csproj.

  5. Right-click on TempUno, then Edit TempUno.csproj. (There is no need to unload this type of project)

  6. Make a temporary copy of the contents of CoolControls.csproj (eg in a Notepad window) - you will refer to this when restoring dependencies.

  7. Copy the entire contents of TempUno.csproj and paste them into CoolControls.csproj, overwriting the old contents.

  8. Delete the TempUno project from your solution.

  9. Right-click on CoolControls, then choose Reload Project.

  10. In the Properties folder of CoolControls, you'll need to remove the AssemblyVersion 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.