gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 17:42:47 25 4
gpt4 key购买 nike

我有目录结构,如 -

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 的文件夹,由于上述问题,它要求我在两个位置添加文件

最佳答案

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 目录中。

关于nuget - 为什么 NuGet 包管理器在多个位置下载/复制包?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31963582/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com