Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setup NuGet packages folder for project outside solution folder

I have the following project structure:

  • \Root
    • \SolutionFolder
      • \App1
        • 📙 packages
        • Program.cs
        • App1.csproj
      • \App1.sln
    • \App2
      • 📗 packages
      • Program.cs
      • packages.config
      • App2.csproj

*Note: App2 project is referenced by App1.
My problem is that whenever I rebuild the solution, the \packages folder containing nuget packages for App2 project, is added to \App1 instead of \App2.
This is a problem because this App2 project is referenced by other solutions as well, not only from App1.
So it is important to have it's own \packages folder and not to have a reference from App2 --> App1, since App2 is shared by other solutions as well.

Update: The App1 has its own nuget packages installed in it's own \packages folder. I want a solution for keeping each project installing nuget packages in its own \packages folder.

like image 349
Ionut Avatar asked Sep 19 '25 18:09

Ionut


1 Answers

You can add NuGet.config file to your solution, which will change default path to the packeges folder:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <config>
    <add key="repositorypath" value="..\..\packages" />
  </config>
</configuration>

Of course you need to put a relative path which is correct in the specific solution. A solution-specific NuGet.Config file should be located within a .nuget folder in the solution.

Here: https://docs.nuget.org/ndocs/consume-packages/configuring-nuget-behavior you have a detailed description of this.

like image 56
Marek Koziorowski Avatar answered Sep 21 '25 10:09

Marek Koziorowski