Configure nuget package sources for your project

Tuyến Vũ
naxam-blogs
Published in
2 min readNov 26, 2017

--

VS Nuget Package Source Manager

Problem

As you might be verify familar with above snapshot: Visual Studio Nuget Package Sources UI, details could be found here. It’s very easy to use, easy to work with. However, if you notice,

  1. It’s system-wide configuration, all configured package sources will be available to your every projects.
  2. It’s machine specific configuration, all of your developers in a project must set up the same to work with packages correctly.
  3. It’s only good for remote based package sources, your packages must be hosted somewhere to be fetched.
  4. It might not work with your CI service

What if you want

  • package sources are configured as per project basis
  • package sources could be located either conventionally on developer machine or on remote server
  • package sources are configured automatically for your project without the developer care
  • package sources must be available for CI service

Solution

It’s provided out-of-the-box by Microsoft, you just need to create a nuget.config file located in your project root folder with all package sources required by your project. This snippet is an example of how you could do it.

In line 4, it specifies that there are packages for the current project located inside folder nugets within current folder.

In line 5, it specifies the package source from Syncfusion.

In line 6, it specifies a private package source requiring a credential to be provide. To achieve that, there is additional configuration inside packageSourceCredentials as you can see from line 12 to 16. If you want to use your enviroment variables or other advanced setup, plz read more details here.

You could create/edit this configuration file manually with either a text editor of choice or through Nuget CLI as details here.

Wrap up

In this post, I have pointed out how you could configure package sources specifically to each of your projects. You could read more details about all elements of a nuget.config file here.

NUGET is the official package manager for .NET libraries, yet it is very powerful. It’s really useful and helpful to deliver your libraries across projects, teams and with the world. Please read it in details here.

--

--