Search code examples
uwpuno-platform

How to reference Windows.Storage from a Uno class library


I'm trying to port a UWP class library to Uno Platfrom but I cannot figure out what references I need in the .csproj file to resolve System.Windows types.

I'm seeing:

error CS0246: The type or namespace name 'Windows' could not be found (are you missing a using directive or an assembly reference?)"

The few samples I've found that reference Windows.Storage don't appear to need anything other than Uno.Core.

I've tried adding <PackageReference Include="Uno.Core" Version="2.3.0" /> to the .csproj file but it doesn't resolve the problem.

What am I missing?


Solution

  • Windows.Storage namespace is part of the UWP API surface which Uno implements on non-Windows targets. It is part of the Uno.UI NuGet package, so you need to reference it to be able to use it.

    The easiest way to accomplish this is to create your class library using the Cross-Platform Library (Uno Platform) template which you will find in the New Project dialog after installing Uno Platform extension in Visual Studio. Such a class library already contains on the necessary configuration a multi-targeted library needs, including the reference to Uno.UI.

    Uno Platform Cross-Platform Library template in New Project dialog