Coder Perfect

In Visual Studio 2015, what is the difference between a Shared Project and a Class Library?


I was looking at the new Visual Studio 2015 capabilities and Shared Project kept popping up, but I’m not sure how it differs from utilizing a Class Library or a Portable Class Library. Is there anyone who can explain this?

Edit: A Portable Class Library is not the same as a Shared Project, which is a new feature in Visual Studio 2015. I’m familiar with the concept of a Portable Class Library. What I’m attempting to figure out is the difference between a Shared Project and a Class Library. Please see the link below for more information.

Asked by Indy411

Solution #1

A shared project differs from a class library in that the latter is compiled and the assembly is the unit of reuse.

The shared code is included into each assembly that references the common project in the former, whereas the source code is the unit of reuse in the latter.

When you wish to create separate assemblies for different platforms but yet have code that should be shared, this is a good option.

See also here:

You could share source code between projects in previous versions of Visual Studio1 by selecting Add -> Existing Item and then Link. However, this was inconvenient because each source file had to be picked separately. With the transition to supporting many platforms (iOS, Android, etc. ), they decided to create the notion of Shared Projects to make it easier to exchange source between projects.

1 This query and my response (to this point) indicate that Shared Projects is a new feature in Visual Studio 2015. They were first introduced in Visual Studio 2013 Update 2.

Answered by Damien_The_Unbeliever

Solution #2

This blog provided me with additional information.

Answered by Indy411

Solution #3

In-Short Differences are

1) Unlike SharedProject, PCL will not have full access to the.NET Framework.

2) #ifdef for platform-specific code – you can’t write in PCL (the #ifdef option isn’t available to you in a PCL since it’s generated independently, as its own DLL, so it doesn’t know what platform it’ll be part of at build time (when the #ifdef is evaluated).) You can do this with a shared project.

3) In PCL, platform specific code is achieved using Inversion Of Control, but in Shared Project, platform specific code is achieved using #ifdef expressions.

The following link leads to a great article that explains the distinctions between PCL and Shared Project.

Xamarin Forms: PCL vs. Shared Project

Answered by Venkataramana Madugula

Solution #4

In a nutshell, as others have already stated:

On a code (file) level, shared project reuse is possible, with folder structure and resources included.

assembly-level pcl reuse

For me, the information on the limited capabilities available in a PCL was generally missing from answers here: for example, you have limited file operations (I was missing a lot of File.IO fuctionality in a Xamarin cross-platform project).

In greater depth, here’s what the shared project entails: + Can use #if when targeting multiple platforms (e.g., Xamarin iOS, Android, WinPhone) + Each target project has access to all framework capabilities (though has to be conditionally compiled) ยท Compile-time integration – somewhat bigger resultant assemblies – Visual Studio 2013 Update 2 or higher required

pcl: + creates a shared assembly + compatible with previous Visual Studio versions (pre-2013 Update 2) o limited functionality – dynamically linked (subset of all projects it is being referenced by)

If you have the option, I recommend going with a shared project because it is more versatile and powerful. You could also go that route if you know your criteria ahead of time and a PCL can meet them. By not allowing you to create platform-specific code, PCL enforces a clearer separation (which might not be a good choice to be put into a shared assembly in the first place).

The main focus of both is when you need to target several platforms; otherwise, you’d just use a regular library/dll project.

Answered by Andreas Reiff

Solution #5

A shared compiled code is referred to as a class library.

The source code for a shared project is shared.

Answered by Shadi Namrouti

Post is based on