对于我的大多数项目,我有以下约定:

/src
    /Solution.sln
    /SolutionFolder
        /Project1
        /Project2
        /etc..
/lib
    /Moq
        moq.dll
        license.txt
    /Yui-Compressor
        yui.compressor.dll
/tools
    /ILMerge
        ilmerge.exe

您会注意到,我没有在源文件夹中保留外部库。我对使用NuGet也很感兴趣,但不希望在源文件夹内使用这些外部库。NuGet是否有一个设置来改变所有包加载到的目录?


当前回答

好吧,为了阅读这篇文章的其他人,以下是我对上述无数答案的理解:

The nuget.config file in the .nuget folder is relative to that folder. This is important because if your new folder is something like '../Packages' that will put it where it always goes out of the box. As @bruce14 states you must do '../../Packages' instead I could not get the latest nuget (2.8.5) to find a packages folder outside of the standard location without enabling package restore. So once you enable package restore then the following should be added to the nuget.config file inside of the .nuget folder to change the location: <?xml version="1.0" encoding="utf-8"?> <configuration> ... <config> <add key="repositoryPath" value="..\..\Packages" /> </config> ... </configuration> (This is important) If you make ANY changes to the package folder location inside of the nuget.config files you must restart visual studio or close/reload the solution for the changes to take effect

其他回答

现在可以控制将包安装到哪个文件夹。

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放置包之前,你需要删除它 新地点。

我又发现了一个小秘密。(这可能是最基本的,有些人还没有提到,但它对我的解决方案很重要。)“packages”文件夹最终与你的.sln文件在同一个文件夹中。

我们移动了.sln文件,然后固定了其中的所有路径,以找到各种项目,瞧!我们的packages文件夹最终位于我们想要的位置。

为了改变项目的路径使用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.config”的文件。 把那个文件加到我的解决方案文件夹里了

这对我不起作用:

<configuration>
  <config>
    <add key="repositoryPath" value="..\ExtLibs\Packages" />
  </config>
  ... 
</configuration>

这对我来说确实有用:

<?xml version="1.0" encoding="utf-8"?>
<settings>
  <repositoryPath>..\ExtLibs\Packages</repositoryPath>
</settings>

这些答案都不适合我(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