Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding reference of another external project in a solution

Using: .net core mvc c#

I have a solution which has a .net mvc core web app & one class library. There is a shared project (class library) that I want to this solution which is a part of different project (different solution as well).

All of these projects are stored in our local GIT repository.

If I add the external project as project dependency in my existing project then there would be 2 copies of the external project that we have to maintain. If some developer updates external project how does the change propogates to other projects using it. And there could be that some developer updates the external project when under its local solution which we want to prevent. Since all are in GIT is it possible somehow to make dependency related so that any change in external is known to others.

So basically how can we prevent anyone to make local updates to the external project but also make sure any updates to external project are available to any other project using them.

like image 261
kaka1234 Avatar asked Dec 04 '17 13:12

kaka1234


People also ask

How do I add a reference to one project to another in Visual Studio code?

Right click on project --> Add Reference --> Select the reference project from the list.

What is a project reference?

A reference project is a write-protected copy of a project at a particular time.


1 Answers

There are several approaches that you can use to achieve this.

Quick: Reference project in two solutions

The quickest is to reference the shared project from both solutions. This way, you can use it in both projects and the changes are propagated to the other solution because you are basically working on the same files. However, a huge drawback of this approach is that if you make changes in solution A that are not compatible with solution B (e.g. removing a method that is used in solution B), you will only find out when working on solution B.

Easy: Single solution

To fix this, you could merge the solutions into a single one that contains the shared proect and also the other projects from solutions A & B. This way, you still get the convenience of project references in a solution. In addition, you are notified about breaking changes immediately if you build the complete solution. If this approach is viable for you in terms of solution size and team structure, I'd favor this approach. As you already share a single Git repository, I think this approach is well worth considering.

Nuget Package

If you want to keep the solutions strictly separated, you'd need to follow a more complex procedure. You could for instance move the shared project into a solution of its own and create a Nuget package with a clear build and versioning strategy. You can host the Nuget package on a package feed (e.g. on Visual Studio Team Services). Solutions A and B can then reference the Nuget package from the feed and also update it if a new version becomes available.

Here the official documentation to create nuget package with nuspec or csproj

Create .NET Standard 2.0 packages with Visual Studio 2017 [CSPROJ]

Creating NuGet packages [NUSPEC]

like image 76
Markus Avatar answered Oct 25 '22 22:10

Markus