Portable Class Library in .NET
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
If you look at the project properties (Alt+Enter), you have option to “Change” or “Select” 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.
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.