20

I want to know the difference between PCL (Portable Class Library) and a normal library.

PCL uses profiles with which it can be determined which platforms and features are available. Both can generate a DLL which can be used on different platforms. For a normal library project you can also set the target framework (e.g. .NET 3.5). Xamarin says that #if compiler directives are only suitable for Shared Projects, which means they are not used in PCL. I think the PCL and the library project are very similar.

So what are the differences, when dealing with different mobile platforms?

Lii
  • 11,553
  • 8
  • 64
  • 88
testing
  • 19,681
  • 50
  • 236
  • 417
  • 2
    Class libraries only target .NET versions. PCLs target multiple platforms so it is even more restrictive. It uses the least common denominator available across all of the platforms targeted. Shared projects are basically just file links back to the project. If you go with PCLs, profiles 78 or 259 are good for targeting the most platforms. – valdetero Feb 26 '15 at 16:40
  • So the difference is that class libraries only target the whole .NET framework and PCL target specific features depending on the operating system and the .NET framework? Can you easily convert one type of project into another? – testing Feb 26 '15 at 18:26
  • 1
    @testing I haven't found an easy way to convert a project from one to the other. The PCL is the ideal way to share code between multiple Xamarin apps. However, if you have dependencies that are not also a PCL, then your PCL cannot reference them. This is where a shared project can help out. It can reference those non-PCL dependencies. – Eric Levine Feb 26 '15 at 19:42

1 Answers1

21

Portable class libraries are platform independent. They do not use conditional compilation and unmanaged code, they have no UI inside (UI is platform dependent). This is because PCL should work on all specified platforms which was chosen as a target. Also, availability of features depends on selected targets.

So a PCL can be referenced by any project which target is specified in the PCL settings. But libraries of other types can be referenced only by projects which have the same target or by upper subsets of .Net (for example, Silverlight libraries can be used in Windows projects but not vice versa).

More about restrictions and features of PCL can be found on two links bellow:

  1. Share functionality using Portable Class Libraries
  2. Cross-Platform Development with the Portable Class Library

On the first link you can read about what is PCL in general. And on second - info about targets and features.

Hope this helps.

EDIT: See also What is a Portable Class Library?

Community
  • 1
  • 1
Yoh Deadfall
  • 2,711
  • 7
  • 28
  • 32
  • And what is the difference between PCL and a library project? – testing Feb 26 '15 at 18:26
  • As @valdetero says a standard library targets to a single platform and a portable class library targets to multiple libraries at the same time. – Yoh Deadfall Feb 27 '15 at 08:38
  • What if the standard library does run on multiple platforms, wouldn't it be the same? – testing Feb 27 '15 at 13:18
  • 1
    No. It's because a PCL can be referenced by any project which target is specified in the PCL settings. But other libraries can be referenced only by projects which have the same target or by upper subsets of .Net (for example, Silverlight libraries can be used in Windows projects but not vice versa). – Yoh Deadfall Feb 27 '15 at 15:09
  • im starter ... is there any sample to connect to SharePoint or MS-CRM or Project server or (json parsing or) web api call template projects that we started from this? – saber tabatabaee yazdi Jul 25 '16 at 14:10