9

I have a number of solutions which share the same projects in different folders, for example,

Common folder
 - common 1
 - common 2
Contracts folder
 - contracts for project A
 - contracts for Project B
Application 1 folder (in this folder I have my solution file)
 - Solution A
 - nuget creates packages folder there
Application 2 folder
 - Solution B
 - nuget creates packages folder there
packages folder( I need this folder at top level, so all projects can reference it)

With this structure Nuget creates two packages folder inside of Application 1 and Application 2

But all of this projects and solutions related to each other, so logically it's better to have only one packages folder.

Is it possible to set in nuget only one folder and use that folder for all solutions?

Or should I structure my solutions and projects another way?

2 Answers 2

7

You can do this by adding nuget.config files to each solution with following contents

<settings>
<repositoryPath>..\Packages</repositoryPath>
</settings>

Make sure that they all point to the same folder.

When you make this file, you have to restart Visual Studio to make it use this setting ( or at least close and open the solution).

But more practical would be to create just one nuget.config that all solutions make use of. Just make sure it resides on a folder higher then any solution file you wish to include. When restoring, the nuget manager searches for this file, starting from next to the solution file and if not found, start looking higher up the folder structure.

3
  • 1
    In latest Nuget, the repositoryPath should be written with forward slashes if it is a relative path. (../Packages) May 16, 2016 at 7:14
  • @Schwarzie2478 I have two different solutions with shared project. If I use the above mentioned settings where exactly it will create the packages folder? Apr 19, 2019 at 7:09
  • a relative value for repositoryPath starts from the location of the nuget.config file itself. So this example would always create a packages folder one folder above the nuget.config file. Apr 19, 2019 at 8:41
0

Sharing a repository between 2 solutions isn't really possible, as if you update a package in solution A the projects in solution b won't be updated unless they're also in solution A (and may have their package automatically deleted because solution A doesn't use them anymore). Basically meaning having 2 solution files is redundant or you're going to break the other solution with no way of knowing.

How are the solutions related to each other? Maybe there's another way to solve the problem if we have a bit more information.

1
  • If I have projects that are related to each other, I always try to have at least a solution that contains them all, so that upgrading packages is less painfull... May 17, 2016 at 7:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.