如何在 Visual Studio 2015 中为多个解决方案和项目设置单个 Nuget 包文件夹 [英] How to setup single Nuget packages folder for multiple solutions and projects in Visual Studio 2015

查看:114
本文介绍了如何在 Visual Studio 2015 中为多个解决方案和项目设置单个 Nuget 包文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在 Visual Studio 2015 中开发多个解决方案.这些解决方案共享一些需要 nuget 包的核心项目.当从一个解决方案添加 nuget 包并稍后由另一个解决方案打开时,无法解析 nuget 引用.

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.

文件夹结构如下:

  • 代码库
    • 共享项目
      • 共享项目1
      • 网络项目A
      • 包文件夹 A
      • WebProjectB
      • 包文件夹 B

      当我在打开 SolutionA 时将 nuget 包安装到 SharedProject1 时,dll 引用显示了 packages 文件夹 A 的路径.在另一台计算机上打开 SolutionB 时,SharedProject1 出现引用错误,因为 packages 文件夹 A 不存在.

      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.

      我已阅读此解决方案:当某些项目包含在多个解决方案中时,为所有解决方案设置一个通用的 nuget 包文件夹 但这并不能解决问题,因为 .nuget 中的 repositoryPath 键/NuGet.config 文件不适用于 Visual Studio 2015Nuget 3.4.3

      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.config 文件放入 Codebase 目录,然后删除所有其他 Nuget.config 文件并解决方案中的 .nuget 文件夹.由于 NuGet 配置会传播到子文件夹,因此单个 NuGet.config 文件中的设置将应用于所有解决方案.

      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.

      在 Nuget.config 文件中,我们放置了 packageSourcerepositoryPath 设置.

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

      示例 NuGet.config 文件:

      Example NuGet.config file:

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

      需要卸载并重新安装现有的 nuget 包,因为 .csproj 文件中的 dll 引用仍将显示旧的 packages 文件夹.或者您可以手动编辑 .csproj 文件.

      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.

      结果文件夹结构:

      • 代码库文件夹
        • Nuget.Config 文件
        • SharedPackages 文件夹
        • SharedProjects 文件夹
          • 共享项目1
          • Codebase folder
            • Nuget.Config file
            • SharedPackages folder
            • SharedProjects folder
              • SharedProject1
              • 网络项目A
              • packages 文件夹 A
              • WebProjectB
              • 包文件夹 B

              这篇关于如何在 Visual Studio 2015 中为多个解决方案和项目设置单个 Nuget 包文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆