Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 990
Tolga Avatar asked Dec 10 '12 08:12

Tolga


People also ask

What is the difference between the portable class library and shared projects?

The difference between a shared project and a class library is that the latter is compiled and the unit of reuse is the assembly. Whereas with the former, the unit of reuse is the source code, and the shared code is incorporated into each assembly that references the shared project.

What is portable class library in C#?

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.

What is Portable Class Library xamarin?

What is a Portable Class Library? When you create an Application Project or a Library Project, the resulting DLL is restricted to working on the specific platform it is created for. This prevents you from writing an assembly for a Windows app, and then re-using it on Xamarin. iOS and Xamarin. Android.

What is a. net Shared project?

What is a Shared Project? The concept of shared projects were introduced in Visual Studio 2013 RC 2, and in a nutshell, allow you to reference an entire project as opposed to just a single assembly like you would with a class library.


1 Answers

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:

  • How to Make Portable Class Libraries Work for You
  • Create Cross-platform Apps with Portable Class Libraries (BUILD session)

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.

like image 193
Daniel Plaisted Avatar answered Oct 21 '22 22:10

Daniel Plaisted