Sharing NuGet Packages Across Projects

by fwhagen Wed, 04 January 2017

Frequently, when developing multiple apps with a shared set of libraries, NuGet package sets can get out of hand. There’s no need for each project or solution to have it’s own set of libraries, and they should definitely not be in the repository.  I found this solution the other day to be most satisfying:

Create a file called nuget.config and place it in a common root directory for all the projects and solutions you want to share it.  Then fill it with the following:

<configuration>
  <config>
    <add key="repositoryPath" value=".\Libraries\packages" />
  </config>
</configuration>

Of course, you can use any value you wish.  I like to keep applications in subdirectories of .\Applications and shared libs in .\Libraries, but that’s me.  the way this works, according to NuGet docs, is the package handler searches for this file locally, then recursively up the folder structure from the project calling it, then a global file in your %appdata% directory.  When the file is absent, it defaults to the familiar behavior of creating the packages subdir in the solutions directory.

This gem has helped me a great deal.  Hopefully you too.

Keywords:

Filed Under: .NET | Programming

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

TextBox

RecentPosts