I have a .NET 6.0 C# class library project that contains platform-independent code (let's call this BusinessLogic
). In my same solution, I would like to create a project for a WinUI 3 app that references this class library (let's call this WindowsApp
). I would also like to create a class library specific to the Windows platform (so I can access the Windows.Storage
namespace from within that class library, for example... let's call this WindowsOS
).
I get an error when attempting to set this up. I have tried two techniques:
First technique
- Create a .NET 6.0 C# class library
WindowsOS
. - In
WindowsOS
project, add reference toBusinessLogic
. No problem. - In
WindowsOS
project, install NuGet packagesMicrosoft.Windows.SDK.BuildTools
andMicrosoft.WindowsAppSDK
. This gives me an error about numeric comparisons on the target platform, similar to the one described in this GitHub issue. Afterwards, the project becomes unloadable in Visual Studio.
Second technique
- Create a Class Library (Universal Windows) project
WindowsOS
. - In
WindowsOS
project, add reference toBusinessLogic
. This gives me an error immediately, simply refusing to allow the reference to be added.
I suspect there appears to be some compatibility issue going on. I reviewed the Microsoft docs on .NET Standard versions, as well as this helpful StackOverflow question about .NET Core vs .NET Standard class libraries, and from what I can tell UWP may not be capable of referencing .NET class libraries.
My end goal is to create a WinUI 3 desktop app that references these cross-platform class libraries. My common code is contained in these libraries, and I may make an Android app or other platform app in a separate project that also references these same cross-platform class libraries. How do I do this?
EDIT: Here is a screenshot of the error from technique #1: