简体   繁体   English

为解决方案文件夹外的项目设置NuGet包文件夹

[英]Setup NuGet packages folder for project outside solution folder

I have the following project structure: 我有以下项目结构:

  • \\Root \\根
    • \\SolutionFolder \\ SolutionFolder
      • \\App1 \\应用1
        • 📙 packages 📙包
        • Program.cs Program.cs中
        • App1.csproj App1.csproj
      • \\App1.sln \\ App1.sln
    • \\App2 \\应用2
      • 📗 packages 📗包
      • Program.cs Program.cs中
      • packages.config packages.config
      • App2.csproj App2.csproj

*Note: App2 project is referenced by App1. *注意:App1引用了App2项目。
My problem is that whenever I rebuild the solution, the \\packages folder containing nuget packages for App2 project, is added to \\App1 instead of \\App2 . 我的问题是每当我重建解决方案时,包含App2项目的nuget包的\\ packages文件夹都会添加到\\ App1而不是\\ App2
This is a problem because this App2 project is referenced by other solutions as well, not only from App1. 这是一个问题,因为这个App2项目也被其他解决方案引用,而不仅仅是来自App1。
So it is important to have it's own \\packages folder and not to have a reference from App2 --> App1, since App2 is shared by other solutions as well. 所以拥有它自己的\\ packages文件夹并且没有来自App2 - > App1的引用是很重要的,因为App2也被其他解决方案共享。

Update: The App1 has its own nuget packages installed in it's own \\packages folder. 更新: App1在其自己的\\ packages文件夹中安装了自己的nuget包。 I want a solution for keeping each project installing nuget packages in its own \\packages folder. 我想要一个解决方案,以保持每个项目在其自己的\\ packages文件夹中安装nuget包。

You can add NuGet.config file to your solution, which will change default path to the packeges folder: 您可以将NuGet.config文件添加到您的解决方案,这将更改packeges文件夹的默认路径:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <config>
    <add key="repositorypath" value="..\..\packages" />
  </config>
</configuration>

Of course you need to put a relative path which is correct in the specific solution. 当然,您需要在特定解决方案中放置一个正确的相对路径。 A solution-specific NuGet.Config file should be located within a .nuget folder in the solution. 特定于解决方案的NuGet.Config文件应位于解决方案中的.nuget文件夹中。

Here: https://docs.nuget.org/ndocs/consume-packages/configuring-nuget-behavior you have a detailed description of this. 这里: https//docs.nuget.org/ndocs/consume-packages/configuring-nuget-behavior您有详细说明。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM