At times you must have came across a situation when you want to share class library (DLLs) across different target platform.  For instance , I faced a situation where I wanted to create a class library and share business logic with WCF service as well as Silverlight application. This means that we want our class library to target different version of framework such as Silverlight. Same is the case with Windows Phone.

Previously, if you have made any class library project containing something that you would like to share across your Silverlight app or WP app or Xbox or web app, Visual Studio would not allow you to add reference of class library project (DLL) in another project targeting other version of .NET framework. The workaround involve rework/duplication resulting in creating multiple projects.

Visual Studio 11 (Beta) has introduced a new project template “Portable Class library” which allows you to create a portable DLL that can be ported with different version of framework 😉

Portable Class Library Template

If you look at the project properties (Alt+Enter), you have option to “Change” or “Select” target frameworks.

Change Target Frameworks

The concept behind the scene is very simple for the reason why it was restricted previously and why it is allowed via this template. Previously, a class library targeting .NET Framework (server) does include references such as System.Data, System.ServiceModel which obviously are not supported in Silverlight runtime or on Windows Phone etc. And as you can anticipate what this new template does is that it restricts you to common references (such as System.dll, System.Core.dll, System.ServiceModel.dll), which can be referred to all versions of .NET framework.

You can also get this template in VS 2010 SP1 and its available via Visual Studio extensions.

Portable Library in VS 2010

In short, Visual Studio 11 has new project template that allows you to create a portable library that can be referred across different target platforms of .NET framework.

There is a recommended article “Create a Continuous Client Using Portable Class Libraries” in MSDN magazine explaining the use of Portable library.

Feel free to share your similar experience and usage of Portable class library in comments form below.


Anonymous · August 15, 2012 at 5:00 pm

It would be nice if you could include System.Data classes for when it’s used with the full framework, but when it’s referenced by say, Windows Phone the IDE and/or the framework just makes those classes unavailable for use.

Sharing Code between Windows Store/Phone Apps using MVVM and PCL · April 6, 2014 at 12:43 am

[…] code base across Windows Phone and Windows Store apps using Model-View-ViewModel (MVVM) pattern and Portable Class Libraries […]

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *