6

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?

4

2 回答 2

7

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.

于 2013-11-14T00:18:17.557 回答
5

如前所述,PCL 强制您仅使用您所针对的所有平台上存在的 API。

此外,字节码是“可移植的”,但 .NET 程序集包含对其他程序集的引用,并且在 PCL 支持出现之前,对 .NET Framework API 的引用使用跨平台的不同程序集标识。IE,对 System.dll 的 .NET Framework 版本的引用将具有与 Windows Phone 或 Silverlight 不同的版本号和强名称密钥。最重要的是,对于某些 API(例如 ICommand 和 HttpWebRequest),程序集的简单名称甚至都不相同。因此,您无法创建可移植到多个平台的程序集。

请在此处查看我的答案以获取一些信息:https ://stackoverflow.com/a/16349673/1509

于 2013-11-14T01:21:11.317 回答