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

时间:2016-05-17 11:18:15

标签: c# .net visual-studio-2015 nuget nuget-package-restore

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

1 个答案:

答案 0 :(得分:13)

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