默認配置: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)