/config/nuget/nuget-config-package-sources
nuget.config packageSources: add a private feed and clear the defaults
- tool
- NuGet
- file
- nuget.config
- key
- configuration/packageSources
- type
- list of <add key=NAME value=URL-or-folder /> elements, optionally preceded by <clear />
- default
- nuget.org (https://api.nuget.org/v3/index.json) from the user-level NuGet.Config
<packageSources> in nuget.config lists the feeds NuGet restores packages from. Each <add key="name" value="url" /> adds a source; a leading <clear /> drops every source inherited from user-level and machine-level config files, so the project uses exactly the feeds listed. Put the file next to the solution and commit it, then check the result with dotnet nuget list source.
Example
mkdir local-packages
cat > nuget.config <<'EOF'
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="local" value="./local-packages" />
</packageSources>
<disabledPackageSources>
<add key="local" value="true" />
</disabledPackageSources>
</configuration>
EOF
dotnet nuget list sourceOutput
Registered Sources:
1. nuget.org [Enabled]
https://api.nuget.org/v3/index.json
2. local [Disabled]
/tmp/work/local-packagesA relative folder path is resolved from the folder that contains the nuget.config. Disabled sources stay in the list but are not queried.
How NuGet combines config files
NuGet reads every nuget.config from the project folder up to the drive root, then the user-level file (%APPDATA%\NuGet\NuGet.Config on Windows, ~/.nuget/NuGet/NuGet.Config on Linux and macOS), then machine-wide files. Sources from all of them are merged unless a closer file uses <clear />.
| Element | Effect |
|---|---|
| <clear /> | Forget sources defined in config files read so far (higher in the chain) |
| <add key="..." value="..." /> | Add a source: an https URL to a v3 index.json, or a local folder |
| protocolVersion="3" | Mark a URL as a NuGet v3 feed |
| <disabledPackageSources> | Keep a source defined but skip it during restore |
| <packageSourceCredentials> | Credentials per source (prefer environment-specific files or credential providers) |
| <packageSourceMapping> | Route package id patterns to specific sources |
Commands that edit the file
dotnet nuget add source https://pkgs.example.com/nuget/v3/index.json --name company
dotnet nuget disable source company
dotnet nuget enable source company
dotnet nuget remove source company
dotnet nuget list sourceWithout --configfile they act on the configuration hierarchy of the current folder; pass --configfile nuget.config to edit the project file explicitly.