简体   繁体   English

如何在 Visual Studio 2015 中为多个解决方案和项目设置单个 Nuget 包文件夹

[英]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:文件夹结构如下:

  • Codebase代码库
    • SharedProjects共享项目
      • SharedProject1共享项目1
    • SolutionA方案A
      • WebProjectA网络项目A
      • packages folder A包文件夹 A
    • SolutionB方案B
      • WebProjectB网络项目B
      • packages folder B包文件夹 B

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.在另一台计算机中打开SolutionBSharedProject1出现引用错误,因为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 2015Nuget 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文件中,我们放置了packageSourcerepositoryPath设置。

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: 结果文件夹结构:

  • Codebase folder Codebase文件夹
    • Nuget.Config file Nuget.Config文件
    • SharedPackages folder SharedPackages文件夹
    • SharedProjects folder SharedProjects文件夹
      • SharedProject1 SharedProject1
    • SolutionA folder SolutionA文件夹
      • WebProjectA WebProjectA
      • packages folder A 包文件夹A.
    • SolutionB SolutionB
      • WebProjectB WebProjectB
      • packages folder B 包文件夹B.

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:在夏天:

  1. Each developer created a single direcrory to store all packages from all solutions.每个开发人员都创建了一个目录来存储来自所有解决方案的所有包。
  2. Then create virtual drive letter in their machine point to that directory.然后在他们的机器上创建虚拟盘符指向那个目录。
  3. Modify global nuget.config at %Appdata%\\NuGet\\NuGet.Config to use new location修改 %Appdata%\\NuGet\\NuGet.Config 处的全局 nuget.config 以使用新位置
  4. Reinstall packages to change HintPath in .csproj files重新安装包以更改 .csproj 文件中的 HintPath
  5. Push changes to source control.将更改推送到源代码管理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Visual Studio 2015多种解决方案策略(TFS) - Visual Studio 2015 multiple solutions strategy (TFS) 在Visual Studio 2015解决方案中恢复所有Nuget包 - Restoring all Nuget Packages in a Visual Studio 2015 Solution 在Visual Studio 2008中复制和修改解决方案(带有安装项目) - Copy and modify solutions (with setup projects) in Visual Studio 2008 如何使用 Visual Studio 2022 为解决方案中的所有项目全局管理 nuget 包? - How to manage nuget packages globally for all projects in a solution using Visual Studio 2022? 如何恢复 Visual Studio nuget 包? - How to restore visual studio nuget packages? 在带有nuget包的Visual Studio中,是否可以在发布时更改.dlls文件夹? - In visual studio with nuget packages is it possible to change the .dlls folder when publishing? 在Visual Studio 2013中的不同解决方案中调试多个项目 - Debugging Multiple Projects which are in different solutions in Visual Studio 2013 如何将选定的 nuget 包中的 dll 复制到 Visual Studio 中的输出文件夹? - How to copy dlls from selected nuget packages to output folder in Visual Studio? 如何在 Visual Studio 项目文件夹中安装/存储 NuGet 包? - How to install/Store NuGet Packages inside the Visual Studio Project's folder? 如何在Visual Studio 2015中设置TypeScript环境 - How to setup TypeScript environment in Visual Studio 2015
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM