为什么NuGet Package manager在多个位置下载/复制软件包?

为什么NuGet Package manager在多个位置下载/复制软件包?,nuget,nuget-package-restore,Nuget,Nuget Package Restore,我的目录结构像- Projects .nuget NuGet.exe NuGet.config NuGet.targets **packages (I want to download package for different solution HERE ONLY)** Sources Applications App1 App1.sln (Solution File)

我的目录结构像-

Projects
   .nuget
      NuGet.exe
      NuGet.config
      NuGet.targets
      **packages (I want to download package for different solution HERE ONLY)**
   Sources
      Applications
         App1
            App1.sln (Solution File)
            **packages (NuGet downloads packages here first then copies to expected folder, WHY??)**
            App1 (Porject Directory)
               App1.csproj
         App2
            App2.sln (Solution File)
            **packages (NuGet downloads packages here first then copies to expected folder, WHY??)**
            App2 (Porject Directory)
               App2.csproj
我使用以下代码引用了每个解决方案中的.nuget文件夹

Project("{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}") = ".nuget", ".nuget", "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx}"
    ProjectSection(SolutionItems) = preProject
        ..\..\..\.nuget\NuGet.Config = ..\..\..\.nuget\NuGet.Config
        ..\..\..\.nuget\NuGet.exe = ..\..\..\.nuget\NuGet.exe
        ..\..\..\.nuget\NuGet.targets = ..\..\..\.nuget\NuGet.targets
    EndProjectSection
EndProject
在每个项目文件(.csproj)中,我都使用

<Import Project="..\..\..\..\.nuget\NuGet.targets" Condition="Exists('..\..\..\..\.nuget\NuGet.targets')" />

在NuGet.config中,我添加了以下行,以便它应该(必须)只复制预期文件夹中的包

<add key="repositoryPath" value="..\packages" />

我用TFS映射了项目文件夹,由于上述问题,它要求我在这两个位置添加文件

NuGet将根据当前解决方案的目录查找

因此,采用App1解决方案如果项目目录位于c:\Projects中,那么App1.sln文件将位于c:\Projects\Sources\Applications\App1目录中。现在,NuGet将在以下位置查找NuGet.config目录:

c:\Projects\Sources\Applications\App1\.nuget\NuGet.Config
c:\Projects\Sources\Applications\App1\NuGet.Config
c:\Projects\Sources\Applications\NuGet.Config
c:\Projects\Sources\NuGet.Config
c:\Projects\NuGet.Config
c:\NuGet.Config
在这之后,它会在机器范围内查找,但我现在将忽略这些

查看目录结构,nuget不会检查Projects.nuget目录。它不是任何解决方案目录的父目录

我将考虑将一个带有repositoryPath设置的NuGet.Config文件放在Sources目录或Projects目录(而不是.NuGet目录)中。或者有两个NuGet.Config文件,一个在App1.NuGet目录下,另一个在App2.NuGet目录下