Setting Up a Common Location for Nuget Packages

Tags: nuget, TFS

Who loves nuget?  Me!  We all should, it’s great.   In my current enterprise environment we were having some annoying occurrences regarding nuget references and libraries.   We have many solutions and many commonly referenced projects.  The common projects were often developed as part of some specific solution and nuget references were added.   This puts the packages folder at the solution root by default and everything is fine and dandy.  However when you add this common package to a different solution, the references are pointing to the original solution directory.  That's often an bothersome broken reference.  If the developer reinstalls the nuget package the reference is fixed. But when they check in the solution, that breaks the references in the original solution!  Not to mention, we would be checking in the nuget libraries into source control again!  We decided a common nuget packages location would be a benefit and eliminate these pesky problems we were having.

 

Shared Location

To set up the shared packages library location, I created a nuget.config file with a custom repositoryPath

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <config>
    <add key="repositoryPath" value="Our TFS root\Common Packages" />
  </config>
</configuration>

This file tells Nuget where the common packages folder is.  I placed the file in our TFS root.  When a developer downloads this config file from TFS and restarts Visual Studio, their Nuget package manager will begin installing new packages to the common packages location and set the assembly references in all projects to point there.  The new Common Packages directory was also checked in to TFS.

 

Existing Solutions

For existing solutions with existing Nuget package libraries, they could be left alone to work as is or updated to use the new packages location.   In order to update a solution to use the new common package location you need to:

  1. Delete the current packages folder
  2. Run Update-Package –reinstall

I just love eliminating irksome exasperations!

No Comments

Add a Comment