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?
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).
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!
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.
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:
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.
(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.
(SCREENSHOT: Add Portable Class Library)
So, now I have a new class library project in my solution:
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:
(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.
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With