1

I need to create a Portable Class Library for use in both Windows Phone 8 & 8.1.

However, I need access to some APIs which are only available in Windows Phone 8.1.

How can I create a library to use in a Windows Phone 8 app that can use the 8.1 APIs if the app is running on an 8.1 device?

kshitijgandhi
  • 1,532
  • 1
  • 16
  • 28
  • If those libraries are only available in Windows Phone 8.1, how would you handle that in Windows Phone 8 devices? – meneses.pt Sep 22 '15 at 13:14

1 Answers1

0

Is it possible to create Portable Class Library for Windows Phone 8 & 8.1?

Yes, it is. Create a new PCL and select Windows Phone Silverlight 8 and Windows Phone 8.1. Visual Studio will probably add automically additional platforms.

How can I create a library to use in a Windows Phone 8 app that can use the 8.1 APIs if the app is running on an 8.1 device?

  • Create a new Solution
  • Add a PCL as described above.
  • Add a new Windows Phone 8 app
  • Add a new Windows Phone 8.1 app
  • Add references to the PCL in both Windows Phone projects
  • Write as much code as possible inside the PCL project
  • Whenever you need to access WP8.1 specific APIs you must create it inside the WP8.1 project.
  • Hide the platform specific code behind a platform independent interface
  • Register the implementation for the interface on startup in a dependency injection container in order to access it inside the PCL. If you don't know which container to use take a look at Which .NET Dependency Injection frameworks are worth looking into?

You will result in one apps for Windows Phone 8.0 and one app for Windows Phone 8.1. The most of your code will probably be inside the PCL. Only platform specific code will stay outside the PCL.

Community
  • 1
  • 1
Wosi
  • 41,986
  • 17
  • 75
  • 82
  • The question you linked is worthless. The OP should use their favorite search engine to find current IoC libraries that support both wp8.0 and 8.1. –  Sep 22 '15 at 14:35
  • @Wosi Do you mean to say that the code inside the PCL would only be the common code supported by both WP8 & WP8.1? I have created a single PCL project and created a dll from it. I need the dll to use both WP8 && WP8.1 code in the same app. – kshitijgandhi Sep 23 '15 at 09:09
  • AFAIK you can not use WP8.1 related APIs in an app that can run also on WP8.0. You need two apps which share as much code as possible in a PCL. – Wosi Sep 23 '15 at 16:03