12

Is anybody explain to me what is the advantage of using portable class libraries instead of using "Add as Link"?

Thanks

Daniel Plaisted
  • 16,674
  • 4
  • 44
  • 56
Tolga
  • 247
  • 1
  • 4
  • 10

1 Answers1

27

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.

Daniel Plaisted
  • 16,674
  • 4
  • 44
  • 56
  • 2
    This answer looks great to me. Only thing I'd add is that the linked file route also adds factor N maintenance issues. When I used to maintain the linked file version of mvvmcross, adding anew platform was a daunting prospect, but now I've switched to PCL code, I'm happily considering adding a couple of new platforms - adding them is not as big or unpleasant a task. – Stuart Dec 11 '12 at 00:05
  • 3
    I lied... There's a couple more things I'd add - 1. that the pcl route encourages testing and makes testing significantly easier; 2. That imo the pcl route encourages good architecture - it encourages the use of interfaces and dependency injection, whereas file linking encourages static linking to classes and #if statements which later cause other builds to break. – Stuart Dec 11 '12 at 00:09
  • We looked at converting over to PCL but I think it really is something that needs to be thought about from day 1. –  Jun 11 '13 at 08:53