I was looking at the new features for Visual Studio 2015 and Shared Project came up a lot but I don't understand how it is different to using a Class Library or a Portable Class Library. Can anyone explain?
Edit: Shared Project is a new feature in Visual Studio 2015 and is different to a Portable Class Library. I understand what a Portable Class Library is. What I'm trying to understand is how a Shared Project differs to a Class Library. See link below.
This question is related to
c#
.net
visual-studio-2015
I found some more information from this blog.
Class library is shared compiled code.
Shared project is shared source code.
From the book VS 2015 succintly
Shared Projects allows sharing code, assets, and resources across multiple project types. More specifically, the following project types can reference and consume shared projects:
Note:- Both shared projects and portable class libraries (PCL) allow sharing code, XAML resources, and assets, but of course there are some differences that might be summarized as follows.
In-Short Differences are
1) PCL is not going to have Full Access to .NET Framework , where as SharedProject has.
2) #ifdef for platform specific code - you can not write in PCL (#ifdef option isn’t available to you in a PCL because it’s compiled separately, as its own DLL, so at compile time (when the #ifdef is evaluated) it doesn’t know what platform it will be part of. ) where as Shared project you can.
3) Platform specific code is achieved using Inversion Of Control in PCL , where as using #ifdef statements you can achieve the same in Shared Project.
An excellent article which illustrates differences between PCL vs Shared Project can be found at the following link
http://hotkrossbits.com/2015/05/03/xamarin-forms-pcl-vs-shared-project/
Like others already wrote, in short:
shared project
reuse on the code (file) level, allowing for folder structure and resources as well
pcl
reuse on the assembly level
What was mostly missing from answers here for me is the info on reduced functionality available in a PCL: as an example you have limited file operations (I was missing a lot of File.IO fuctionality in a Xamarin cross-platform project).
In more detail
shared project:
+ Can use #if when targeting multiple platforms (e. g. Xamarin iOS, Android, WinPhone)
+ All framework functionality available for each target project (though has to be conditionally compiled)
o Integrates at compile time
- Slightly larger size of resulting assemblies
- Needs Visual Studio 2013 Update 2 or higher
pcl:
+ generates a shared assembly
+ usable with older versions of Visual Studio (pre-2013 Update 2)
o dynamically linked
- lmited functionality (subset of all projects it is being referenced by)
If you have the choice, I would recommend going for shared project, it is generally more flexible and more powerful. If you know your requirements in advance and a PCL can fulfill them, you might go that route as well. PCL also enforces clearer separation by not allowing you to write platform-specific code (which might not be a good choice to be put into a shared assembly in the first place).
Main focus of both is when you target multiple platforms, else you would normally use just an ordinary library/dll project.
Source: Stackoverflow.com