NuGet.Config precedence: project‑level vs solution‑level packageSources
0 reputation · 24 Jul 2021, 05:53 UTC
0 reputation · 24 Jul 2021, 05:53 UTC
Determine which NuGet.Config file is consulted when a project and its solution both define the same packageSources key.
The official precedence list states that project‑level settings should override solution‑level ones, yet the documentation does not clarify whether the value is replaced or merged. In practice, when both files contain a packageSources entry, the restore log sometimes shows duplicate URLs, suggesting a merge rather than an override.
packageSources, does the project value fully replace the solution value, or are the two lists concatenated?packageSources entry?When both a solution‑level .nuget\NuGet.Config and a project‑level NuGet.Config define a packageSources entry with the same key, the project‑level value completely replaces the solution‑level value. The lists are not concatenated; only the later file’s entry for that key is kept.
packageSources section, later files override earlier entries that share the same key.<clear/> element before re‑adding desired sources in the project file achieves that effect..nuget\NuGet.Config with a source, e.g.:<configuration>
<packageSources>
<add key="SolutionSrc" value="https://solution.example" />
</packageSources>
</configuration>NuGet.Config next to the project file. For the same key:<configuration>
<packageSources>
<add key="SolutionSrc" value="https://project.example" />
</packageSources>
</configuration>For a different key, just add another <add> element.dotnet restore -v detailed (or msbuild -t:Restore) and examine the log for lines like "Adding package 'SolutionSrc' with value ...".<clear/> before the project’s <add> element.Confirm the version of the dotnet CLI/NuGet you are using (e.g., dotnet --version). The override rule described applies to NuGet 3.x and later; older NuGet.exe versions may exhibit different merging behavior.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.