[英]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.我们正在 Visual Studio 2015 中开发多个解决方案。这些解决方案共享一些需要 nuget 包的核心项目。 The nuget references cannot be resolved when the nuget package is added from one solution and is later opened by another solution.
当从一个解决方案添加 nuget 包并稍后由另一个解决方案打开时,无法解析 nuget 引用。
The folder structure is as follows:文件夹结构如下:
When I install a nuget package to SharedProject1
when SolutionA
is opened, the dll reference shows the path to the packages folder A
.当我在打开
SolutionA
时将 nuget 包安装到SharedProject1
时,dll 引用显示packages folder A
的路径。 When SolutionB
is opened in another computer, SharedProject1
has a reference error since the packages folder A
doesn't exist.在另一台计算机中打开
SolutionB
, SharedProject1
出现引用错误,因为packages folder A
不存在。
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
我已经阅读了这个解决方案: 当某些项目包含在多个解决方案中时,为所有解决方案设置一个通用的 nuget 包文件夹,但这并不能解决问题,因为 .nuget/NuGet.config 文件中的
repositoryPath
键未应用于Visual Studio 2015
和Nuget 3.4.3
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. 要解决此问题,我们将NuGet.config文件放入
Codebase
目录,然后删除解决方案中的所有其他Nuget.config文件和.nuget文件夹。 Since NuGet configurations are propagated to sub folders, the settings in the single NuGet.config file are applied into all the solutions. 由于NuGet配置传播到子文件夹,因此单个NuGet.config文件中的设置将应用于所有解决方案。
Inside the Nuget.config file we put the packageSource
, repositoryPath
settings. 在Nuget.config文件中,我们放置了
packageSource
, repositoryPath
设置。
Example NuGet.config file: 示例NuGet.config文件:
<?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. 由于.csproj文件中的dll引用仍将显示旧的
packages
文件夹,因此需要卸载并重新安装现有的nuget包。 Or you can manually edit the .csproj files. 或者您可以手动编辑.csproj文件。
Resulting folder structure: 结果文件夹结构:
Here is complete description on what we have done: Force a reference to be absolute using Visual Studio以下是对我们所做工作的完整描述: Force a reference to be absolute using Visual Studio
In summery:在夏天:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.