Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to setup single Nuget packages folder for multiple solutions and projects in Visual Studio 2015

We are developing multiple solutions in Visual Studio 2015. The solutions share some core projects that need nuget packages. The nuget references cannot be resolved when the nuget package is added from one solution and is later opened by another solution.

The folder structure is as follows:

  • Codebase
    • SharedProjects
      • SharedProject1
    • SolutionA
      • WebProjectA
      • packages folder A
    • SolutionB
      • WebProjectB
      • packages folder B

When I install a nuget package to SharedProject1 when SolutionA is opened, the dll reference shows the path to the packages folder A. When SolutionB is opened in another computer, SharedProject1 has a reference error since the packages folder A doesn't exist.

I have read this solution: Setting up a common nuget packages folder for all solutions when some projects are included in multiple solutions but this doesn't solve the problem since the repositoryPath key in the .nuget/NuGet.config file is not applied with Visual Studio 2015 and Nuget 3.4.3

like image 653
Hüseyin Yağlı Avatar asked May 17 '16 11:05

Hüseyin Yağlı


People also ask

How do I install NuGet from another project?

Simply copy existing packages. config file to your new project. Include this file into the project. Then follow to Package Manager Console and execute Update-Package -reinstall command.

How do I manage NuGet packages in Visual Studio?

Set up Visual StudioIn Visual Studio, select Tools, and then select Options. Select NuGet Package Manager, and then select Package Sources. Enter the feed's Name and Source URL, and then select the green (+) sign to add a new package source. If you enabled upstream sources in your feed, clear the nuget.org checkbox.


1 Answers

To resolve the issue, we put a NuGet.config file into the Codebase directory then deleted all the other Nuget.config files and .nuget folders in the solutions. Since NuGet configurations are propagated to sub folders, the settings in the single NuGet.config file are applied into all the solutions.

Inside the Nuget.config file we put the packageSource, repositoryPath settings.

Example NuGet.config file:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <config>
        <add key="repositoryPath" value="./SharedPackages" />
    </config>
</configuration>

Existing nuget packages need to be uninstalled and reinstalled since the dll references in .csproj files will still show the old packages folder. Or you can manually edit the .csproj files.

Resulting folder structure:

  • Codebase folder
    • Nuget.Config file
    • SharedPackages folder
    • SharedProjects folder
      • SharedProject1
    • SolutionA folder
      • WebProjectA
      • packages folder A
    • SolutionB
      • WebProjectB
      • packages folder B
like image 133
Hüseyin Yağlı Avatar answered Oct 06 '22 00:10

Hüseyin Yağlı