1

I added in the same place where my .sln file is a nuget.config with this configuration

<packageSources>
    <add key="local repo" value="C:\myproject\nugetRepository" />
</packageSources>

and i also have the default nuget.config in appdata/roaming/NuGet with the following configuration

<packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>

Reading online I understood that having the nuget.config in my root project should overwrite the default one but, instead when building using MSBuild it always uses the one in appdata! How can i specify to use the one in the root project?

andrea
  • 47
  • 1
  • 12

1 Answers1

4

As this page of NuGet's docs says, settings are accumulated, meaning both are used. As mentioned in this section, you can use <clear /> to ignore sources from all previously read nuget.config files.

<packageSources>
    <clear />
    <add key="local repo" value="C:\myproject\nugetRepository" />
</packageSources>

<clear /> is also valid in the disabled package sources and fallback folders sections, which is important for engineering teams to who repeatable builds are absolutely critical (eg, someone sharing the same CI machine and writing a nuget.config to c:\ is unacceptable to affect your own team's build).

zivkan
  • 12,793
  • 2
  • 34
  • 51
  • Great, like this it works, thanks! Like this tho is always ignoring the first one right? Is there a way, instead, to ignore the first one (if failing, for example i don't have internet connection) and fallback on the second one? – andrea Apr 27 '20 at 12:52