.net 什么是可移植类库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5238955/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is a Portable Class Library?
提问by mjcopple
On MSDN I noticed a section about a Portable Class Library, under Version Information.
在 MSDN 上,我注意到Portable Class Library在版本信息下有一个关于 a 的部分。
See System.Objectfor an example. http://msdn.microsoft.com/en-us/library/system.object.aspx
参见System.Object示例。http://msdn.microsoft.com/en-us/library/system.object.aspx
I did a brief Google search and couldn't find anything about the Portable Class Library. Does anyone here know what it is or where I could find more information about it?
我做了一个简短的谷歌搜索,找不到任何关于Portable Class Library. 这里有没有人知道它是什么或者我可以在哪里找到有关它的更多信息?
采纳答案by Ruben Bartelink
UPDATE Oct 9 2017: Article comparing/constrasting .NET Core/Std/PCLUPDATE Nov 23 2016: Article by Rick Strahl
2017 年 10 月 9 日更新:文章比较/对比 .NET Core/Std/PCL2016 年 11 月 23 日更新:Rick Strahl 的文章
UPDATE Oct 29 2016: .NETStandard 1->2 FAQUPDATE Oct 19 2016: This is the best interview/video I've seen to date covering .NET Standard 2.0
2016 年 10 月 29 日更新:.NETStandard 1->2 常见问题解答2016 年 10 月 19 日更新:这是迄今为止我见过的关于 .NET Standard 2.0的最佳采访/视频
UPDATE Sep 27 2016: .NET Standard 2.0 announcement posthas more good info
2016 年 9 月 27 日更新:.NET Standard 2.0 公告帖子有更多好的信息
UPDATE Jun 6 2016: This articleexplains well how the .NETStandard library mechanism supersedes much of PCL
2016 年 6 月 6 日更新:本文很好地解释了 .NETStandard 库机制如何取代大部分 PCL
UPDATE Jul 10 2013: Excellent state of the PCL union summary blogpost from @shanselmanwith lots of concrete examples, screenshots and links. Puts any other answer here in the shade.
2013 年 7 月 10 日更新:来自 @shanselman 的 PCL 联盟摘要博客文章的出色状态,其中包含许多具体示例、屏幕截图和链接。将任何其他答案放在阴影中。
UPDATE May 20 2013:
2013 年 5 月 20 日更新:
- Very practical coverage of practical application and implications of this for cross-device stuff (think Xamarin Studio) in Tablet Show podcast with Atley Hunter. Key takeaway:- PCLs are a very useful constraint to impose on onself in cross-device scenarios.
- One of the libraries mentioned wrt that is the excellent MvvmCross which is discussed in a separate Tablet Show Episode 71with it's author @Stuart Lodge. Only minor tweaking as described by Stuart hereto environment setup is necessary to leverage PCLs for such purposes.
- 在Atley Hunter 的 Tablet Show 播客中,非常实用地介绍了实际应用及其对跨设备内容的影响(想想 Xamarin Studio)。关键要点:- PCL 是一个非常有用的约束,可以在跨设备场景中强加给自己。
- 其中一个库提到了 wrt,它是优秀的 MvvmCross,它在单独的 Tablet Show 第 71 集中与其作者@Stuart Lodge 进行了讨论。只需对环境设置进行 Stuart 所描述的微小调整,即可将 PCL 用于此类目的。
UPDATE Apr 19 2013: Excellent dense summary of how it all hangs together from Intellisense through to run time in a blog post by Simon Cooper
2013 年 4 月 19 日更新:在Simon Cooper的博客文章中,对从 Intellisense 到运行时间的所有内容如何结合在一起进行了出色的密集总结
Video: Channel 9 Visual Studio Toolbox show episode 14 June 2012
视频:第 9 频道 Visual Studio Toolbox 节目,2012 年 6 月 14 日
Video: Channel 9 Going Deep Show episode 27 Sep 2011
UPDATE Sep 11 2012: Good high level blog post with pictures, diagrams and motivating examples showing how MVVM Light and RX use it
2012 年 9 月 11 日更新:很好的高级博客文章,其中包含展示 MVVM Light 和 RX 如何使用它的图片、图表和激励示例
UPDATE Apr 11 2012: Very good end to end piece by Scott Hanselman that gets to the point in dev speak very quickly including screenshots here(also contains very insightful 'how to think of it' information and links to samples). Also includes a resources section at the end that pretty much duplicates this entire post :D
2012 年 4 月 11 日更新:Scott Hanselman非常好的端到端文章,它在开发中非常快速地讲到了重点,包括此处的屏幕截图(还包含非常有见地的“如何思考”信息和示例链接)。最后还包括一个资源部分,几乎重复了整篇文章:D
UPDATE Jul 9 2012: This blog series by Mircea Trofin of the dev team (one part so far) is the most completecoverage yet, including screenshots and detailed matrices showing available features across your selections if you're into that sort of thing.
2012 年 7 月 9 日更新:这个由开发团队的 Mircea Trofin 撰写的博客系列(迄今为止的一部分)是迄今为止最完整的报道,包括屏幕截图和详细矩阵,如果您喜欢这类事情,则可以在您的选择中显示可用功能。
See Portable Library Tools anouncement blog post, which starts:-
请参阅便携式库工具公告博客文章,其中开始:-
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.
可移植库工具 CTP 向 Visual Studio 添加了一个新的“可移植类库”项目模板,该模板可用于在 C# 和 VB 中创建类库,无需重新编译即可在各种 .NET 平台上运行。
It's used for creating a Class Library that targets multiple platforms (esp Silverlight variants such as WP7 and SL4, but including XNA on Xbox) at one time.
它用于同时创建一个面向多个平台(尤其是 Silverlight 变体,如 WP7 和 SL4,但包括 Xbox 上的 XNA)的类库。
See also this InfoQ summary article
另见这篇InfoQ 摘要文章
See also this release notice.
另请参阅此发布通知。
For down and dirty details, see Multi-Targeting Guidelines for Tools for Managed Code
有关失败和肮脏的详细信息,请参阅托管代码工具的多目标指南
回答by Shekhar_Pro
The Portable Class Library project enables you to write and build managed assemblies that work on more than one .NET Framework platform. You can create classes that contain code you wish to share across many projects, such as shared business logic, and then reference those classes from different types of projects.
Portable Library Tools is a new Visual Studio add-in from Microsoft that enables you to create C# and Visual Basic libraries that run on a variety of .NET-based platforms without recompilation.
可移植类库项目使您能够编写和构建在多个 .NET Framework 平台上运行的托管程序集。您可以创建包含您希望在多个项目中共享的代码(例如共享业务逻辑)的类,然后从不同类型的项目中引用这些类。
便携式库工具是来自 Microsoft 的一个新的 Visual Studio 加载项,它使您能够创建在各种基于 .NET 的平台上运行的 C# 和 Visual Basic 库,而无需重新编译。
MSDN now has a nice article/documentation on it. You can check it out and see what is supported in Portable Class Library
.
MSDN 现在有一篇很好的文章/文档。您可以查看它并查看.Portable Class Library
The following assemblies are available within a Portable Class Library project:
- mscorlib.dll
- System.dll
- System.Core.dll
- System.Xml.dll
- System.ComponentModel.Composition.dll
- System.Net.dll
- System.Runtime.Serialization.dll
- System.ServiceModel.dll
- System.Xml.Serialization.dll
- System.Windows.dll (from Silverlight)
可移植类库项目中提供以下程序集:
- mscorlib.dll
- 系统文件
- 系统核心文件
- 系统文件
- System.ComponentModel.Composition.dll
- 系统.Net.dll
- 系统.运行时.序列化.dll
- 系统服务模型.dll
- 系统.Xml.Serialization.dll
- System.Windows.dll(来自 Silverlight)
You can find which members are supported by the Portable Class Library project in the reference topics for the .NET Framework Class Library. In the members table for a class, the following Portable Class Library icon appears next to supported members.
您可以在 .NET Framework 类库的参考主题中找到可移植类库项目支持哪些成员。在类的成员表中,以下可移植类库图标显示在受支持的成员旁边。
(Icon for the Portable Class Library which you will see in MSDN Docs.)
(您将在 MSDN 文档中看到的可移植类库的图标。)
To create a Portable Class Library Project you need to have :
要创建可移植类库项目,您需要:
1. Visual Studio 2010 Service Pack 1 (SP1)(795KB Installer, 1.48GB ISO)
2. Portable Library ToolsCTP (1.38MB)
1. Visual Studio 2010 Service Pack 1 (SP1)(795KB 安装程序,1.48GB ISO)
2. 便携式图书馆工具CTP (1.38MB)
After Installing Above updates you will get a new Project Template for Portable Class Library :
安装上述更新后,您将获得可移植类库的新项目模板:


(Above Contents taken from MSDN)
(以上内容摘自MSDN)
UPDATE 2014:
2014 年更新:
Class Library Portable is part of Visual Studio 2014.
Class Library Portable 是 Visual Studio 2014 的一部分。
回答by Darin Dimitrov
It's a class library that can run on various platforms.
它是一个可以在各种平台上运行的类库。
回答by AmiNadimi
I found Documents a bit hard to understand so i tried to make things a little clear here.
我发现文档有点难以理解,所以我试图在这里把事情说清楚。
Portable Class library is built to let programmers create projects that will run over multiple platforms like Xbox 360, Windows Phone, Silverlight and .NET Framework (4 and above). this is done through omitting some specific API's that is not supported by your chosen target platforms that will cause you to lose some available features of .Net Framework.
可移植类库旨在让程序员创建可在多个平台上运行的项目,如 Xbox 360、Windows Phone、Silverlight 和 .NET Framework(4 及更高版本)。这是通过省略一些您选择的目标平台不支持的特定 API 来完成的,这些 API 会导致您丢失 .Net Framework 的一些可用功能。
So we can say, choosing between Portable class libraryand Normal class librarydepends on target platforms of your project. if you want your app to work on Xbox and Desktop Computers with windows operating system, you better save your time and use PCL, other than that Normal class library will do fine.
所以我们可以说,在Portable class library和 Normal之间进行选择class library取决于您项目的目标平台。如果您希望您的应用程序在 Windows 操作系统的 Xbox 和台式计算机上运行,您最好节省时间并使用 PCL,除此之外,Normal 类库也可以。
for more information visit documentation page.
有关更多信息,请访问文档页面。
Now there is a new and open source technology called .Net Standard which will displace PCL. .NET Standard solves the code sharing problem for .NET developers across all platforms by bringing all the APIs that you expect and love across the environments that you need: desktop applications, mobile apps & games, and cloud services:
现在有一种新的开源技术称为 .Net Standard,它将取代 PCL。.NET Standard 解决了 .NET 开发人员在所有平台上的代码共享问题,将您期望和喜爱的所有 API 引入您需要的环境:桌面应用程序、移动应用程序和游戏以及云服务:
- .NET Standard is a set of APIs that all .NET platforms have to implement. This unifies the .NET platforms and prevents future fragmentation.
- .NET Standard 2.0 will be implemented by .NET Framework, .NET Core, and Xamarin. For .NET Core, this will add many of the existing APIs that have been requested.
- .NET Standard 2.0 includes a compatibility shim for .NET Framework binaries, significantly increasing the set of libraries that you can reference from your .NET Standard libraries.
- .NET Standard will replace Portable Class Libraries (PCLs) as the tooling story for building multi-platform .NET libraries.
- .NET Standard 是一组所有 .NET 平台都必须实现的 API。这统一了 .NET 平台并防止了未来的碎片化。
- .NET Standard 2.0 将由 .NET Framework、.NET Core 和 Xamarin 实现。对于 .NET Core,这将添加许多已请求的现有 API。
- .NET Standard 2.0 包含一个适用于 .NET Framework 二进制文件的兼容性垫片,显着增加了您可以从 .NET Standard 库中引用的库集。
- .NET Standard 将取代可移植类库 (PCL) 作为构建多平台 .NET 库的工具故事。
You can see the .NET Standard API definition in the dotnet/standard repo on GitHub.
您可以在 GitHub 上的 dotnet/standard 存储库中查看 .NET Standard API 定义。

