简体   繁体   English

使用便携式类库而不是使用“添加为链接”有什么好处?

[英]What is the advantage of using portable class libraries instead of using “Add as Link”?

Is anybody explain to me what is the advantage of using portable class libraries instead of using "Add as Link"? 是否有人向我解释使用便携式类库而不是使用“添加为链接”的优势是什么?

Thanks 谢谢

Disadvantages of linked files: 链接文件的缺点:

  • Add as link can be hard to maintain, especially as you scale to multiple projects and many source files. 添加为链接可能很难维护,尤其是当您扩展到多个项目和许多源文件时。 Tooling (such as Project Linker for Visual Studio 2010, or holding ALT while dragging in Visual Studio 2012) can make this easier. 工具(例如Visual Studio 2010的Project Linker,或在Visual Studio 2012中拖动时保持ALT)可以使这更容易。
  • Refactoring tools don't work with linked files. 重构工具不适用于链接文件。 For example, if you rename a class or method in a linked file, refactoring tools won't update references to other linked copies of that API. 例如,如果重命名链接文件中的类或方法,则重构工具不会更新对该API的其他链接副本的引用。
  • When editing code in a linked file, intellisense may show you APIs that are not available on all the platforms the file is linked into. 在链接文件中编辑代码时,intellisense可能会向您显示在文件链接到的所有平台上都不可用的API。
  • Visual Studio will give you a message box saying "This document is opened by another project" when you try to open a linked file already opened by another project. 当您尝试打开另一个项目已打开的链接文件时,Visual Studio将为您提供一个消息框,说明“此文档由另一个项目打开”。
  • You end up with a separate DLL for each platform. 最终,每个平台都有一个单独的DLL。 If you are creating a reusable library you would like to share with others, it might be easier to distribute if there was just one version of it, not a separate one for each platform. 如果您要创建一个可重用的库,您希望与其他人共享,如果只有一个版本,则可能更容易分发,而不是每个平台的单独版本。

Disadvantages of Portable Class Libraries: 便携式类库的缺点:

  • You are limited to APIs that are available on all the platforms you are targeting. 您仅限于在您定位的所有平台上都可用的API。 You can't use conditional compilation ( #if statements) to get around differences between the platforms 您不能使用条件编译( #if语句)来解决平台之间的差异
  • It can be hard to figure out what APIs are supported on a given combination of platforms. 很难弄清楚给定的平台组合支持哪些API。 Here is a spreadsheet which can help with this: Portable Class Library API List 这是一个电子表格,可以帮助解决这个问题: 可移植类库API列表

For some guidance on how to take advantage of Portable Class Libraries, see the following: 有关如何利用可移植类库的一些指导,请参阅以下内容:

While I'm partial to Portable Class Libraries (as a member of the PCL team), linked files are also an entirely valid way of sharing code and if you don't run into or don't mind the drawbacks, then go ahead and use linked source files. 虽然我偏爱可移植类库(作为PCL团队的成员),但链接文件也是一种完全有效的共享代码的方式,如果你没有遇到或不介意这些缺点,那么请继续使用链接的源文件。 I mostly use Portable Class Libraries, but I still use linked source files when PCLs don't fit. 我主要使用可移植类库,但是当PCL不适合时我仍然使用链接的源文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM