为什么NuGet包管理器在多个位置下载/复制包?

时间:2015-08-12 11:13:57

标签: 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)
            **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)中,我使用了

引用了常见的NuGet.targets
<Import Project="..\..\..\..\.nuget\NuGet.targets" Condition="Exists('..\..\..\..\.nuget\NuGet.targets')" />

在NuGet.config中,我添加了以下行,以便它(必须)仅在EXPECTED文件夹中复制包

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

我已将项目文件夹与TFS映射,并且由于上述问题我要求我在这两个位置添加文件

1 个答案:

答案 0 :(得分:0)

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

因此,如果Projects目录位于c:\ Projects中,则使用App1解决方案,然后您的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目录。它不是任何解决方案目录的父级。

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

相关问题