Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Revision as of 16:57, 5 February 2014 by influencer (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Preparing for Multi-Platform Apps with Portable Class Libraries

From Wiki
Jump to: navigation, search

This article introduces the Portable Class Library template that can help you write code that will run on multiple Windows platforms

WP Metro Icon Tools.png
SignpostIcon XAML 40.png
WP Metro Icon WP8.png
SignpostIcon WP7 70px.png
Article Metadata
Created: influencer (07 Sep 2012)
Last edited: influencer (05 Feb 2014)



The similarities between the app frameworks and the development environments for Windows Phone 8 and Windows 8 are very helpful if you develop for multiple platforms.

However in order to port an app to run on both platforms it is still necessary to redesign the XAML code and copy/paste the code-behind. Maintenance is also difficult - if you add a feature or fix a bug in one solution you have redo the same in the other solution, costing time and effort.

This article introduces a new project template called Portable Class Library that helps writing code for multiple platforms. This is present by default in Visual Studio 2012, and can be added as an extension to VS2010.

Use cases

The functions in the portable parts of .Net Framework are mostly suited for implementing the data layer and the business logic of your apps. You will still need to port your XAML!

If there are classes missing in the PCL that are not available on all platforms the articles (see below) propose either using interfaces or abstract classes that need to be implemented for each platform. This way you can access features that are implemented differently on the diverse platforms.

Supported Platforms

The supported platforms are:

Platform Versions
.NET Framework .NET Framework 4 and higher

.NET Framework 4.0.3 and higher .NET Framework 4.5 (selected by Default)

Silverlight Silverlight 4 and higher (selected by default)

Silverlight 5

Windows Phone Windows Phone 7 and higher (selected by default)

Windows Phone 7.5 and higher

Windows Phone 8

.NET for Windows Store apps N/A
Xbox 360 N/A
  • Note -> For Visual Studio 2010 users – and for Windows Phone 7 development - a Visual Studio "add-in" is available for download, as "Portable Library Tools 2", - at Visual Studio Gallery, The latest release version is 10.0.50828.


When creating a new Portable Class Library project, you can select the platforms your library shall support. This decision influences the classes and APIs that are available in the library.

Add portable Class Library Dialog


Using a portable library for designing a WP7 app can efficiently simplify your work if you want to port to Windows 8. I hope the development of your app version for Windows Phone 8 can also gain from using a portable library for the kernel of your apps.

Recent experiences

Using the PCL in a real project revealed that there are some limitations. For example I tried to use an ArgumentOutOfRangeException Constructor (String, Object, String) in a library I created for .Net 4.5, Silverlight, Win8 Store and Windows Phone 7.5. The MSDN documentation says this ctor is compatible with PCL but trying to use it in the project shows that Intellisense doesn't offer it. The ctor is not available in my project. I used another constructor as workaround. I bugged this in Microsoft Connect and got the response that it is too complex to document in MSDN and I should rely on Intellisense (Connect bug feedback). This happened with other classes and functions, too.

I found out that a Codeplex project is in the ways that tries to cover the missing parts in the Portable Class Libraries, PCL Contrib. Hopefully the limitations can be eliminated... There is no download available yet (Update: I missed it because there are no binaries, just source code: PCL Contrib Source Code). But the project coordinators (among them the main PCL developer David Kean of Microsoft) invite us to enter wishes for new library functions as new bug reports. We should do this and ask the missing parts from them!

Latest development: I asked Dave Kean, why there are Portable Class Libraries that are missing many functions and there is another project that fills in some oft the gaps, both from the same author. I got the reply yesterday. Dave wrote: " The biggest major reason is because this project covers APIs that we consider legacy or deprecated (such as BackgroundWorker). Shipping something in .NET implies that it will be supported, documented and serviced for as long the product itself is (which as it ships in Windows 8 is a long, long time)."

Hey, that's news for me! Even the latest 4.5 documentation (BackgroundWorker Class) doesn't say anything about deprecation.

Another new thing I learned from this reply was where to propose new features for Visual Studio. I always thought Connect was the platform for proposals but there is something else: UserVoice. He wrote: "What we choose to support, is entirely based on customer feedback, so if you have suggestions, please add them over".

  • (.ctor => parameterless constructor)
This page was last modified on 5 February 2014, at 16:57.
62 page views in the last 30 days.