Portable Class Library

What is Portable Class Library

Is is basically used for creating and reusing the libraries through the project and the cross platform applications. PCL is available in the Visual Studio and the Xamarin Studio.Portable Class Libraries allow you to write code and produce libraries that can be shared across mulitple platforms including Xamarin.iOS, Xamarin.Android and Windows Phone. Portable Class Libraries (PCLs) can be created in both Xamarin Studio and Visual Studio, and then referenced in each platform-specific project to allow code to be easily shared.

When you create an Application Project or a Library Project, the resulting DLL is restricted to working on the specific platform it is created for. This prevents you from writing an assembly for a Windows app, and then re-using it on Xamarin.iOS and Xamarin.Android.

The table below shows some of the features that vary by .NET platform. To write a PCL assembly that is guaranteed to run on specific devices/platforms you simply choose which support is required when you create the project.


Creating a PCL to share code has a number of pros and cons versus the File-Linking alternative:
Benefits
  1. Centralized code sharing – write and test code in a single project that can be consumed by other libraries or applications.
  2. Refactoring operations will affect all code loaded in the solution (the Portable Class Library and the platform-specific projects).
  3. The PCL project can be easily referenced by other projects in a solution, or the output assembly can be shared for others to reference in their solutions.
Disadvantages
  1. Because the same Portable Class Library is shared between multiple applications, platform-specific libraries cannot be referenced (eg. Community.CsharpSqlite.WP7).
  2. The Portable Class Library subset may not include classes that would otherwise be available in both MonoTouch and Mono for Android (such as DllImport or System.IO.File).

No comments:

Post a Comment