Difference between Shared project and Class Library Project in Visual Studio 2015

Difference between Shared project and Class Library Project in Visual Studio 2015

Visual Studio 2015 introduced a new type of project template – Shared Project. In one of our previous post, we have seen a Shared Project can be used across multiple applications in Visual Studio, such as with Windows Phone apps , Windows Store apps , Desktop applications, Console applications, or even using Windows Universal applications. This is a great way of sharing code across single Cross Platform applications.  So, What is the different between the  Shared Project and a Class Library ? They looks like exactly same –Isn’t just Shared project a class library? What differs?” – I have received the same question in my previous post . This post will give you an high level view on the difference between Shared Project and Class Library, how they being used, how they are differ with respect to development.

To understand it better way, lets consider below example, where we have one Console Application (ConsoleApplication1), which having Reference of one Class Library (ClassLibary1) and another is a Shared Project(SharedProject1)

Windows Shared Project and Class Library in a Single Solution

Now, in a very first looks, the way SharedProject1 and ClassLibray1 Referred are different.  The Class Library, referred like an Assembly (dll) where as Shared Project Referred as Reference Project which can be imported later.

When,  Shared Project Compiled, there is no binary / dlls that needs to be referred. Though it is referred to the solution, it is considered as single project items that can be imported later.  The Class Library, complied to a dll and that referred with the project.

Let’s have a take a deep look on how they referred in the project.  Open the ConsoleApplication1.csproj files in edit mode and you will find following entries:

Project Reference for Class Library

Reference of Class Libray in a Project

Project Reference for a Shared Project

 

Reference of a Shared Project as Import Project

This clearly say, reference and access of these items are difference. Now, take another level of look. Open the ConsoleApplication1.exe in IL DASM Tool and review the reference as shown in below picture.

Console Application has

  • MANIFEST
  • Application Entity (ConsoleApplication1)
  • And the Shared Project as its own contain )

Shared Project in IL DASM

If you open the MANIFEST file, you would be able to see, ClassLibrary1 referred as an external  assembly.

Application MANIFEST

This actually gives you a clear idea on reference of Class Library and Shared Project.

Difference Between Class Library and Shared Project

In the other hands, with respect to the application development

  •  Supported file types for a Shared Project includes C#, HTML, XAML, JavaScript, Images, Resource etc. This gives lot of advantage when you are building one Desktop Application using WPF,  and a Windows Universal App that uses Shared Project to share the common XAML, Styles, etc.
  • If you want to write platform specific code  ( for Windows Phone , for Windows Store app ) you can use different processor predictive  within the shared project.

processor predictive

Hope this Helps

Abhijit Jana

Abhijit runs the Daily .NET Tips. He started this site with a vision to have a single knowledge base of .NET tips and tricks and share post that can quickly help any developers . He is a Former Microsoft ASP.NET MVP, CodeProject MVP, Mentor, Speaker, Author, Technology Evangelist and presently working as a .NET Consultant. He blogs at http://abhijitjana.net , you can follow him @AbhijitJana . He is the author of book Kinect for Windows SDK Programming Guide.

One Comment to “Difference between Shared project and Class Library Project in Visual Studio 2015”

  1. Nice article on showing the differences ,if I understood your 2 articles correctly, it seems Shared Project works best with universal apps and those who write platform-specific code, I’m not sure how Shared Project would do any good to web sites let’s say web forms,if I have to modify something on Shared project,I have to do a full publish of my webforms website since Shared project won’t build an assembly (dll),in my opinion this is not good,class library on the other hand is useful in this scenario,just make your change,build your project ,then overwrite the assembly dll in your website with the updated one then your website is good to go

Comments are closed.