Adding Sitecore References via Nuget Packages

Posted 01/26/2017 by Ed Kapuscinski

Sitecore announced something very exciting (at least for developers) at last year's Sitecore Symposium: they will make the Sitecore DLLs that we always have to reference in our projects available as NuGet packages.

NuGet Logo

This isn't a huge earth shattering thing (like introducing machine learning into the product), it's one of those little things that makes being a Sitecore developer such a pleasure.

Previously, Sitecore developers would need to somehow reference the DLLs that are part of a Sitecore installation when setting up a Visual Studio project. That was sometimes a simple process, but in complex development environments (especially those using continuous integration or delivery), it could become quite problematic. 

By having these DLLs available in NuGet packages, we can now tell our projects to use them, and anything that can build the project can handle resolving the references for us.

Adding these packages is very easy and all done through the NuGet Package Manager in Visual Studio (Tools => NuGet Package Manager => Manage NuGetPackages for Solution).

First, you need to establish a Sitecore NuGet Package Source. This is done by clicking the little gear icon next to the package source dropdown in the "Manage Packages for Solution" console. Click the "plus" icon, and add the URI of the package source from Sitecore (from this page: Make sure to give your source a name (I simply used "Sitecore"). Hit OK when you're done.

Visual Studio Package Sources

With that complete, select the Sitecore source in the dropdown. This will show you all of the available packages from the source. 

List of available Sitecore NuGet packages

There are a few that you'll almost always want to use: Sitecore.Kernel and Sitecore.Mvc. It may be tempting to use the simple "Sitecore" one, which should install everything you need, but in my experience it always fails while trying to resolve its dependencies.

Click on one of those packages, and then, on the right side of the console, choose the projects for which it should be installed. Make sure to choose the appropriate version that represents the version of Sitecore that your application will be running with. It defaults to the most recent stable, but that's almost always not what you're going to want. 

Sitecore NuGet package version selector

With your projects selected, simply click "Install". That will download the packages, any dependencies it can resolve, and add the reference to your projects. In my experience, if you're converting a project using the old style of references, it will automatically update them for you. 

Repeat the above process for any of the other packages you may need, and you're off to the races.

Also, don't forget to save your solution, so it will update all of the appropriate project and config files to use the new references. These will likely need to be committed to your source control system as well, which is the entire point: replacing environment specific references with ones that will work globally.