Using Shared Project across multiple applications in Visual Studio 2015

Using Shared Project across multiple applications in Visual Studio 2015

Shared Project is a great way of sharing common code across multiple application  We already have experienced with the Shared Project type in Visual Studio 2013 as part of Windows 8.1 Universal App Development, But with Visual Studio 2015, it is a Standalone New Project Template; and we can use it with other types of app like Console, Desktop, Phone, Store App etc.. This types of project is extremely helpful when we want to share a common code, logic as well as components across multiple applications with in single platform. This also allow to access the platform specific API’s , assets etc.

image

Let’s have a look how we can use the Shared Project Template with help of simple application and flow.

Check out all great features of Visual Studio 2015

Create The Shared Project

Run a New Instance of Visual Studio 2015 –> File –> New Project

Navigate to Templates –> Visual C# , there you will find “Shared Project” C# Template.

Creating a Shared Project
Creating a Shared Project

P.S : If you Search template with “Shared Project”, you would also see “Shared Project” of type VB and Java Script.

Once you create a new Project, it will create a Shared Project in Solution Explorer like below

First look of Shared Project
First look of Shared Project

Add a new class Student.

Adding a Simple Class in Shared Project
Adding a Simple Class in Shared Project

Your Shared Project is ready.

 

Using Shared Project – Console Application

Add a new Console Application in the Solution.  Add the SharedProject1 as Reference, from the References –> Shared Projects –> Solution

 

Using Shared Project in a Console Application
Using Shared Project in a Console Application

This will add the “SharedProject1” as reference to the Console Application Solution.

Using Shared Project in a Console Application
Using Shared Project in a Console Application

Now onwards, you can use it just like other application as application reference.

Using Shared Project in a Console Application
Using Shared Project in a Console Application
Using Shared Project in a Console Application
Using Shared Project in a Console Application

 

Using Shared Project – Windows Store App

Similar to Console Application, You can add the Shared Project for Windows Store App and can use it.

Using Shared Project in a Console Application
Using Shared Project in a Console Application

Using Shared Project – Windows Phone App

Create a new Windows Phone App, Added the Shared Project as Reference, and use it,

Using Shared Project in a Console Application
Using Shared Project in a Console Application

Incase of you are trying it with Existing Universal App, You should be able add this as reference as well

Using Shared Project in a Console Application
Using Shared Project in a Console Application

 

Similarly you can try this out for other application as well.  The example of Student class is very simple, but just think in terms of power of this project types when you have lot of shared code, business rules .

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.

4 Comments to “Using Shared Project across multiple applications in Visual Studio 2015”

Comments are closed.