Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling a Windows 10 Universal Class Library from a desktop application

Tags:

In previous development, I have used a Portable Class Library to share code between a Windows 8.1 "Metro" app and a .NET/WPF desktop app.

Are Windows 10 Universal class libraries also usable from such desktop apps, and if not, what is the recommended way to share code in this scenario?

like image 885
Cerebrate Avatar asked Jul 29 '15 21:07

Cerebrate


People also ask

How do I use Universal Windows app?

Step 1: Go to Visual Studio 2015 update 3. Open Visual Studio New-->New project -->select Visual C# --->select Windows -->Universal -->select Blank Windows Universal App and give your app; a name (ex: sample). Step 2: Next step is to select the target version of Windows 10 SDK (Windows 10 Build 10240).

How do I know if my app is UWP?

If the file location is the WindowsApps folder in Program Files, or Windows 10 refuses to open the folder, then it is a UWP App, because Win32 apps are stored in their own folder in Program Files (x86) and 64bit applications are stored in their own folder in Program Files . . . Power to the Developer!

How does UWP app work?

UWP apps work well with multiple types of input such as keyboard, mouse, touch, pen, and Xbox One controllers. If you need to further tailor your UI to a specific screen size or device, new layout panels and tooling help you design UI that can adapt to the different devices and form factors that your app may run on.


1 Answers

First, let's take a look at the first part of your question:

Are Windows 10 Universal class libraries also usable from such desktop apps?

To answer this, I created a new solution in VS2015 with the following projects:

  • WPF desktop app, named wpfApp
  • Win10 UWP app, named win10App
  • Win10 UWP class library, named win10Lib

I was then able to add the class library as a reference to the UWP app. But, I got an error message when trying to add the library reference to the desktop application.

enter image description here

(SCREENSHOT: Err msg when trying to add UWP lib as ref to desktop app)

Next, the second part of your question:

and if not, what is the recommended way to share code in this scenario?

So, I then added a new Class Library project, but not the Universal kind... I selected the Portable Class Library option under Classic desktop apps. This allowed me to choose what platform(s) I want to support, including .NET 4.6 and Windows Universal 10.0.

enter image description here

(SCREENSHOT: Add Portable Class Library)

So, now I have a new class library project in my solution:

  • classic desktop class library (portable), named portableLib

I started adding a class library reference to my WPF desktop app once again, selecting my new portableLib project. However, I got the following error message:

enter image description here

(SCREENSHOT: Error message when adding portable class library ref to WPF project)

This happened because I selected 4.6 (the default for .NET Framework version) as one of the platforms while creating the class library, but my WPF project was still targeting an older version of the .NET Framework. I fixed this by editing the WPF app's project properties and updated the target to match the class library's framework version.

Finally, I added a reference to the new portable class library to my Win10 UWP app, and it got added successfully. I can now build the solution with no errors.

Here is a screenshot of my project structure, with references. enter image description here

Hope this helps!

like image 126
Shahed C - MSFT Avatar answered Sep 28 '22 10:09

Shahed C - MSFT