Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
309 views
in Technique[技术] by (71.8m points)

.net - 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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.
  • 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.
  • 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.
  • 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.
  • You end up with a separate DLL for each platform. 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. You can't use conditional compilation (#if statements) to get around differences between the platforms
  • It can be hard to figure out what APIs are supported on a given combination of platforms. Here is a spreadsheet which can help with this: Portable Class Library API List

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. I mostly use Portable Class Libraries, but I still use linked source files when PCLs don't fit.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...