0

A WPF project and a UWP project share the same solution. Can both projects reference a common project?

  • "Common" - .NET 6 target framework, class library
  • "UWP" - targets Windows 10 Creators Update (Build 15063)
  • "WPF App" - .NET 6 target framework, references "WPF2"
  • "WPF2" - .NET 6 target framework

The "WPF" project can reference "Common" no problem, but the "UWP" project says "Unable to add a reference to project 'Common'".

unable to add a reference

Annoyingly, the error message does not give a reason why.

How to use a class from one C# project with another C# project

Common controls for UWP and WPF

Reference a class library from UWP and ASP.NET 5 (solution here)

Denis G. Labrecque
  • 1,023
  • 13
  • 29

1 Answers1

1

UWP is not compatible with .NET Core or .NET 6.

If you want to share code between a WPF app and a UWP app, your shared project should target .NET Standard 2.0.

Please refer to the docs for more information about .NET Standard and the supported .NET implementations for each version.

mm8
  • 163,881
  • 10
  • 57
  • 88
  • Furthermore, an error message may appear saying that the Class Library cannot be referenced if the .NET Standard version is too advanced for the UWP Windows minimum targeted build. A simple downgrade in the Class Library properties > Application > Target framework solves this. – Denis G. Labrecque Apr 21 '22 at 14:22
  • This looks to me like it should be the solution, but there are using statement referencing issues. Working that out. – Denis G. Labrecque Apr 21 '22 at 14:27
  • Which .NET Standard you can target depends on which version of the UWP you are targeting. As stated in the docs I linked to, .NET Standard 2.0 is compatible with UWP 10.0.16299. – mm8 Apr 21 '22 at 14:34
  • There were some issues with VS not recognizing the reference to the common class, had to remove the reference, build, restart VS before it worked. – Denis G. Labrecque Apr 21 '22 at 14:38
  • This entire setup is complete and utter twaddle – Richard Hammond Mar 25 '23 at 07:32