What is a Portable Class Library?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
A Portable Class Library (PCL) is a project type in Microsoft's .NET Framework that allows developers to write and build cross-platform libraries optimized for execution on multiple .NET platforms such as .NET Framework, .NET Core, Xamarin, and Windows Store apps. The primary goal of PCLs is to provide code-sharing capabilities across different environments by creating a single library that can be used without modifications.
Technical Explanation
A PCL is essentially a subset of the .NET Framework that compiles into a library (usually with a `.dll` extension) that can be referenced by projects targeting multiple .NET platforms. It's important to note that PCLs can only use functionality that's common to all the intended target platforms.
Platform Agnosticism
The key to PCLs is their platform-agnostic nature, which involves three main components:
- Targeting Multiple Frameworks: When creating a PCL, you select the frameworks you want to support. PCL will include only the functionalities shared by those frameworks. For instance, if you target .NET Framework 4.5 and Windows 8, only APIs common to both will be usable.
- Limited API Surface: Due to targeting multiple frameworks, a PCL's API surface is limited to the intersection of APIs available across all platforms. This often means some .NET features, such as certain file I/O operations, are not available in a PCL.
- Binary Compatibility: The output library from a PCL project is in a binary form that is compatible with all selected target platforms. You avoid writing separate platform-specific libraries and implement a single codebase.
Example PCL Usage
Consider a situation where you have a common data processing logic, like calculating a set of statistics, that you want to use in a Xamarin.Android app, a Windows desktop application, and a web service:
- Code Reusability: Centralizes and reuses a single implementation of shared logic.
- Easier Maintenance: Consistent logic facilitates easier bug fixes and feature improvements.
- Simplified Deployment: One library to manage and deploy across various platforms.
- Restricted API Surface: Limited to functionalities supported by all chosen platforms.
- Complexity in Compatibility: Choosing incompatible platforms can restrict usable APIs even further.
- Deprecation: With the advent of .NET Standard, PCLs are considered deprecated, and it's recommended to use .NET Standard for new projects due to its broader applicability and support.
Related reading
- What is a Predicate Delegate and where should it be used?
- What is a predicate in c?
- What is a proper implementation of the IAsyncResult interface?
- What is a quick way to force CRLF in C / .NET?
- What is a replacement method for Task.Run in .NET 4.0 using C?
- What is a singleton in C?
- What is a .snk for?
- What is a 'workspace' in Visual Studio Code?

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.