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)
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
Project Reference for a Shared 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
- Application Entity (ConsoleApplication1)
- And the Shared Project as its own contain )
If you open the MANIFEST file, you would be able to see, ClassLibrary1 referred as an external assembly.
This actually gives you a clear idea on reference of Class Library and Shared Project.
In the other hands, with respect to the application development
- 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.
Hope this Helps