Search code examples
nuget

Scripted way to add nuget package source


We want to start a company nuget package repository. Is there a way to add a package source through command line so we can configure our new package source through a setup or something?

We basically don't want to go

Tools - Options - Package Manager - Package Sources - Plus button - add name and source

on every developer machine in the company.


Solution

  • The package sources are stored in NuGet.config under the user's profile or system wide in ProgramData:

    %AppData%\NuGet\NuGet.config
    %ProgramData%\NuGet\NuGetDefaults.config
    

    You can add package sources through NuGet using a command line similar to:

    nuget sources add -name FeedName -Source http://YourFeed.com
    

    The above command will work if you run it under the user's profile.

    NuGet 2.7 introduced system wide package source configuration in ProgramData. So you could add your package sources into NuGet.config under ProgramData with your installer.