Question

There are pretty many articles about what are PCL like this.

However, from all what I found, they just mostly say something like:

The Portable Library Tools CTP adds a new "Portable Class Library" project template to Visual Studio that can be used to create class libraries in C# and VB that run on the various .NET platforms without recompiling.

But carefully read this superb explanation of how .NET (and Mono) works, I became even more unclear why PCLs even needed.

Because if I've built some Assembly and it contains CIL bytecode (which can be used through any other platform (if corresponding platform has CLR implementation (as the main idea of .NET was))), then what's the problem? Why we would then also need the PCLs?

Was it helpful?

Solution

Although the IL may be the same, the available libraries are not. If you want to target a desktop computer, a Windows 8 app, and Silverlight, you want to ensure that your code uses things that are actually present in all of those places.

Portable Class Libraries ensure that you only use that set of libraries that are applicable to your selected platforms.

You may want to read more details on this .Net Framework blog from a year or so ago.

OTHER TIPS

As mentioned, PCLs enforce that you only use APIs that are present on all the platforms you are targeting.

Also, the bytecode is "portable", but .NET assemblies contain references to other assemblies, and before PCL support came around, the references to .NET Framework APIs used different assembly identities across platforms. IE, a reference to the .NET Framework version of System.dll would have a different version number and strong name key than on Windows Phone or Silverlight. On top of that, for some APIs (for example ICommand and HttpWebRequest), the simple name of the assembly wasn't even the same. So you couldn't create an assembly that was portable to multiple platforms.

See my answer here for a bit of info: https://stackoverflow.com/a/16349673/1509

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top