Default package source for NuGet defaulting to newly added source and not All or nuget.org

16,715

Can anyone tell me how to default to All instead of having it always default to Internal nuget?

To my knowledge, the default package source of NuGet Package Manager depends on the order of package source and the property of activePackageSource in nuget.config.

The order of package source:

When you open NuGet Package Manager setting, Tools->Options->NuGet Packager Manager->Package Source, you will notice that there are up and down arrows for package source:

enter image description here

NuGet Package Manager will give priority for default NuGet package source in the top of the package source list. For example, if I set NuGet package source LocalServer at the top of that list, when I create a new project, the default NuGet source will be changed to LocalServer:

enter image description here

However, this priority of default NuGet source can easily be broken by the property of activePackageSource in nuget.config.

Open the nuget.config file from %appdata%\NuGet\NuGet.config, add the following code:

  <activePackageSource>
    <add key="LocalServer2" value="D:\LocalServerTest" />
  </activePackageSource>

Restart Visual Studio, then create a new project, you will find the default NuGet source change to the LocalServer2:

enter image description here

So, if you want to default nuget.org instead of having it always default to Internal nuget, you can set the NuGet source nuget.org at top of NuGet source list or set the nuget.org as activePackageSource in the nuget.config:

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

Update for comment:

Is there no way to default to All? Maybe you can suggest defaulting to All (looks like you work for MS)

if you want to set the default NuGet source to All, you can use the setting below in nuget.config:

  <activePackageSource>
    <add key="All" value="(Aggregate source)" />
  </activePackageSource>
Share:
16,715

Related videos on Youtube

Mario
Author by

Mario

Updated on June 04, 2022

Comments

  • Mario
    Mario almost 2 years

    I added a NuGet 'Package source' to Visual Studio since we have an internal server at work.

    Visual Studio now always defaults to my internal server and cannot find most of our NuGet packages until I switch the package source to All or nuget.org.

    This is a minor inconvenience, but for the past few weeks, I have been doing many more clicks every time I need to work with the NuGet package manager. Can anyone tell me how to default to All instead of having it always default to Internal nuget?

    nuget defaults to internal package server

  • Mario
    Mario over 6 years
    appreciate the response. I had the order correct but the <activePackageSource in %appdata%\NuGet\NuGet.config was incorrect. I still had to open VS again, select the drop down (probably another nuget.config override), close then open. This is better than it was, but an even better solution would be to default to All. Is there no way to default to All? Maybe you can suggest defaulting to All (looks like you work for MS)
  • Leo Liu
    Leo Liu over 6 years
    @Mario, if you want to set the default nuget source to All, you can use this command in the activePackageSource:<add key="All" value="(Aggregate source)" />. I will update it in the answer. Thanks for your reminding.
  • Alexander Derck
    Alexander Derck about 6 years
    @LeoLiu-MSFT Looks like the 'All' option is deprecated sadly enough docs.microsoft.com/en-us/nuget/reference/…