对于我的大多数项目,我有以下约定:
/src
/Solution.sln
/SolutionFolder
/Project1
/Project2
/etc..
/lib
/Moq
moq.dll
license.txt
/Yui-Compressor
yui.compressor.dll
/tools
/ILMerge
ilmerge.exe
您会注意到,我没有在源文件夹中保留外部库。我对使用NuGet也很感兴趣,但不希望在源文件夹内使用这些外部库。NuGet是否有一个设置来改变所有包加载到的目录?
为了改变项目的路径使用PackageReference而不是包。配置你需要使用globalPackagesFolder
从https://learn.microsoft.com/en-us/nuget/reference/nuget-config-file
globalPackagesFolder (projects using PackageReference only)
The location of the default global packages folder. The default is
%userprofile%.nuget\packages (Windows) or ~/.nuget/packages
(Mac/Linux). A relative path can be used in project-specific
nuget.config files. This setting is overridden by the NUGET_PACKAGES
environment variable, which takes precedence.
repositoryPath (packages.config only)
The location in which to install NuGet packages instead of the default $(Solutiondir)/packages
folder. A relative path can be used in project-specific nuget.config
files. This setting is overridden by the NUGET_PACKAGES environment
variable, which takes precedence.
<config>
<add key="globalPackagesFolder" value="c:\packageReferences" />
<add key="repositoryPath" value="c:\packagesConfig" />
</config>
我放了Nuget。配置旁边的解决方案文件,它工作。
这些答案都不适合我(Nuget 2.8.6),因为缺少一些提示,我会尝试在这里添加它们,因为它可能对其他人有用。
阅读以下资料后:
https://docs.nuget.org/consume/NuGet-Config-Settings
https://github.com/NuGet/Home/issues/1346
看来
To make working Install-Package properly with different
repositoryPath you need to use forward slashes, it's because they are using Uri object to parse location.
Without $ on the begining it was still ignoring my settings.
NuGet caches config file, so after modifications you need to reload solution/VS.
I had also strange issue while using command of NuGet.exe to set this option, as it modified my global NuGet.exe under AppData\Roaming\NuGet and started to restore packages there (Since that file has higher priority, just guessing).
如。
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
<config>
<add key="repositorypath" value="$/../../../Common/packages" />
</config>
</configuration>
你也可以使用NuGet命令来确保语法是正确的,就像这样:
NuGet.exe config -Set repositoryPath=$/../../../Common/packages -ConfigFile NuGet.Config
现在可以控制将包安装到哪个文件夹。
http://nuget.codeplex.com/workitem/215
编辑:
请看Phil Haack在2010年12月10日晚上11:45的评论(在工作项/上面的链接中)。该支持在1.0中部分实现,但没有文档记录。
@dfowler表示:
加一块鸡块。配置文件旁边的解决方案与此:
<settings>
<repositoryPath>{some path here}</repositoryPath>
</settings>
有一个用于创建包文件夹覆盖的nuget包。
版本2.1的更新
正如阿扎特所评论的,现在有关于如何控制包裹位置的官方文件。2.1版本的发布说明在一个nuget中指定了以下配置。配置文件(关于放置配置文件的有效位置以及分层配置模型如何工作的描述,请参阅发布说明):
<configuration>
<config>
<add key="repositoryPath" value="C:\thePathToMyPackagesFolder" />
</config>
...
</configuration>
这将更改您放入文件的配置级别的packages文件夹(解决方案,如果您将其放在解决方案目录中,项目在项目目录中等等)。注意,发布说明声明:
[…如果您的解决方案下面有一个现有的packages文件夹
在NuGet放置包之前,你需要删除它
新地点。