Migrating a UWP-only 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 with Visual Studio for Windows, or another supported IDE such as VS Code.

Applying Uno Platform project structure

Turning a UWP-only class library into an Uno cross-platform 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 UWP-only library you wish to convert.

  2. Create a Cross-Platform Library (Uno Platform) 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 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.