12

we are playing with Nuget and want to setup a private package source (on an internal webserver). I've followed the following instructions to add it to visual studio - (See package sources) https://docs.nuget.org/consume/Package-Manager-Dialog

I'm wondering if there's a way of scripting this outside Visual studio. (I could automatically add it to VS when I rebuild a new workstation)

1
  • Removed 2013 from question title as it works on 2015.3 Commented Jul 29, 2016 at 22:22

3 Answers 3

22

NuGet package sources are stored in a NuGet.Config file that can be stored in three different places:

  1. User profile
  2. With the solution itself.
  3. Machine wide in ProgramData: %ProgramData%\NuGet\Config*.config

For the user profile the package sources are stored in the file:

%AppData%\NuGet\NuGet.Config

When you add the package source in Visual Studio this is where the package source will be saved.

For each solution Visual Studio will look in several directories for the NuGet.Config file before using the one from the user's profile. With a solution in the directory c:\Projects\MySolution then NuGet will look for this file in the directories:

  • c:\Projects\MySolution.nuget\nuget.config
  • c:\Projects\MySolution\nuget.config
  • c:\Projects\nuget.config
  • c:\Projects\nuget.config
  • c:\nuget.config

Machine wide package sources are shown in the Machine-wide section of the dialog in Visual Studio. Visual Studio will look in following directories:

  • %programdata%\NuGet\Config\IDE\Version\SKU*.config
  • %programdata%\NuGet\Config\IDE\Version*.config
  • %programdata%\NuGet\Config\IDE*.config
  • %programdata%\NuGet\Config*.config
  • %ProgramData%\NuGet\Config\IDE*.config
  • %ProgramData%\NuGet\Config*.config

Note that IDE will be replaced with VisualStudio. The Version will be replaced by the Visual Studio version number. The SKU will be replaced with Ultimate, Pro, Professional or Premium.

To programatically add package sources to an NuGet.Config file you could use NuGet.exe which allows you to add or update package sources using a command line similar to:

nuget.exe sources add|update -Name [name] -Source [source]

Or you can use another tool to update the XML in the NuGet.Config file.

Sign up to request clarification or add additional context in comments.

2 Comments

So I think I'll be lazy and just pre-configure the - Microsoft.VisualStudio.config and just create a cmd file to do a quick copy from a share to %ProgramData%\Nuget\Config\VisualStudio\12.0
On a VSTS build, one might want to execute "nuget.exe" sources remove -Name "source name", and afterwards nuget.exe sources add -Name "source name" -Source "C:\...". Just updating would obviously cause the builds to fail, because the source was never defined. (+1)
2

This might help you... talks about configuring NuGet.Targets by default and pushing it to all dev machines...

http://blogs.msdn.com/b/nijain/archive/2013/05/23/visual-studio-package-restore-option-and-custom-nuget-repository.aspx

1 Comment

The link you provided points to - docs.nuget.org/consume/nuget-config-file which provides the location of the nuget configuration file. I guess I'll write up a powershell script to update the config file
0

For those who just need to add a package manager to their own development environment: In Visual Studio click Tools | Nuget Package Manager | Package Manager Settings Then under Package Sources you can enter the new source.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.