If, like me, you are working on multiple projects that reference the same packages (StructureMap is a great example) you may have noticed that each project has its own version of each package.
In this bite sized post, we will look at how to redefine where your packages get installed.
Root source control folder
Here was my root source control folder before making any changes.
When I dive into each folder, I see a packages folder, which contains each of my packages. Generally I use the same packages across multiple projects. What I would like is to be able to create a folder at the root level, called Library and place all my packages in there.
Achieving this takes a bit of effort at first, but will pay off in no time. Go ahead and create the Library folder at the root level. Then for each project, go into the project folder and add a new file called NuGet.config.
The contents of NuGet.config should match as follows;
<?xml version="1.0" encoding="utf-8"?> <settings> <repositoryPath>..Library</repositoryPath> </settings>
Your project folder should now look like this;
The painful bit
Now to finish the job, you must do the following for each project;
- Open the project
- Uninstall all the packages (ensuring all the references are removed)
- Delete the bin directory
- Delete the original packages folder
- Re-add each package
- Save and build
I hope you find this useful, doing this has certainly tidied up my Team Foundation Server (TFS).