默认配置:api
默认配置文件的路径%APPDATA%\NuGet\NuGet.Config (DOS) 或 $ENV:APPDATA\NuGet\NuGet.Config (PowerShell),(例如 D:\Users\username\AppData\Roaming\NuGet\NuGet.config)咱们能够增长配置文件修改默认配置,ui
默认的配置文件以下:this
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<activePackageSource>
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
</activePackageSource>
</configuration>spa
配置文件说明:(http://docs.nuget.org/docs/reference/nuget-config-settings)代理
1. 自定义nuget 包路径。code
<config>
<add key="repositorypath" value="C:\Temp" />
</config>xml
2。自动检查缺失包和自动恢复blog
<packageRestore>
<!-- Allow NuGet to download missing packages -->
<add key="enabled" value="True" />
<!-- Automatically check for missing packages during build in Visual Studio -->
<add key="automatic" value="True" />
</packageRestore>utf-8
3.执行包寻找路径ci
PackageSources:指定包来源地址
DisabledPackageSources:禁止的来源地址
ActivePackageSource:指定为”(Aggregate source)“为除了禁止的来源地址的全部包来源地址
<packageSources>
<add key="NuGet official package source" value="https://nuget.org/api/v2/" />
<add key="TestSource" value="C:\Temp" />
</packageSources>
<disabledPackageSources />
<activePackageSource>
<add key="All" value="(Aggregate source)" />
</activePackageSource>
4。禁止源代码管理整合
<configuration>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
</configuration>
5. 其余,代理设置 ,身份验证设置,设置API Key 访问包来源
完整的实例
<?xml version="1.0" encoding="utf-8"?> <configuration> <config> <!-- Used to specify the default location to expand packages. See: NuGet.exe help install See: NuGet.exe help update --> <add key="repositorypath" value="External\Packages" /> <!-- Used to specify default source for the push command. See: NuGet.exe help push --> <add key="DefaultPushSource" value="http://MyRepo/ES/api/v2/package" /> <!-- Proxy settings --> <add key="http_proxy" value="host" /> <add key="http_proxy.user" value="username" /> <add key="http_proxy.password" value="encrypted_password" /> </config> <packageRestore> <!-- Allow NuGet to download missing packages --> <add key="enabled" value="True" /> <!-- Automatically check for missing packages during build in Visual Studio --> <add key="automatic" value="True" /> </packageRestore> <!-- Used to specify the default Sources for list, install and update. See: NuGet.exe help list See: NuGet.exe help install See: NuGet.exe help update --> <packageSources> <add key="NuGet official package source" value="https://nuget.org/api/v2/" /> <add key="MyRepo - ES" value="http://MyRepo/ES/nuget" /> </packageSources> <!-- used to store credentials --> <packageSourceCredentials /> <!-- Used to specify which one of the sources are active --> <activePackageSource> <!-- this tells only one given source is active --> <add key="NuGet official package source" value="https://nuget.org/api/v2/" /> <!-- this tells that all of them are active --> <add key="All" value="(Aggregate source)" /> </activePackageSource> <!-- Used to disable package sources --> <disabledPackageSources /> <!-- Used to specify default API key associated with sources. See: NuGet.exe help setApiKey See: NuGet.exe help push See: NuGet.exe help mirror --> <apikeys> <add key="http://MyRepo/ES/api/v2/package" value="encrypted_api_key" /> </apikeys> </configuration>
(http://docs.nuget.org/docs/reference/nuget-config-settings)
自定义配置文件寻找规则:
1.nuget默认配置文件链,默认配置文件(nuget.config)路径——当前磁盘根目录——当前目录。
当前目录指:nuget.exe 执行的目录或者当前解决方案加载的目录。
2.nuget.config配置文件读取顺序,
例:当前解决方案的路径为c:\a\b\c,那么配置文件的加载加载规则以下
nuget 2.6之后扩展了部分加载规则,除了上述的路径外,还会从如下路径寻找
( http://docs.nuget.org/docs/reference/nuget-config-file)