问题
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
- SharedProjects
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:
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
来源:https://stackoverflow.com/questions/37274599/how-to-setup-single-nuget-packages-folder-for-multiple-solutions-and-projects-in