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

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

您会注意到,我没有在源文件夹中保留外部库。我对使用NuGet也很感兴趣,但不希望在源文件夹内使用这些外部库。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>

其他回答

Visual Studio 2015上Nuget 3.2的解决方案是:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <config>
        <add key="repositoryPath" value="../lib" />
    </config>
</configuration>

为父文件夹使用正斜杠。 将上述文件(nuget.config)保存在解决方案文件夹中。

参考资料可在此查阅

除了Shane Kms的答案,如果你已经激活Nuget包还原,你编辑Nuget。在.nuget文件夹中的配置如下:

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

注意多余的“..”“\”,因为它从.nuget文件夹而不是解决方案文件夹返回。

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

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

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

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

为了改变项目的路径使用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。配置旁边的解决方案文件,它工作。