Mike Robbins

Sitecore Developer Blog

Follow me on GitHub

How to use Sitecore Nuget

If you have ever used NuGet within any of your Visual Studio projects you will know how easy it is install 3rd party dependencies, update them and bring new developers onto a project, Wouldn't it be useful to take advantage of NuGet in Sitecore.

With the power of Nuget and Powershell you can add files to your solution, add files to the inetpub folder containing your website and best of all insert items directly into the master database of your Sitecore instance.

To create a custom NuGet Package i use NuGet Package explorer. Its a friendly GUI for creating, updating and publishing NuGet packages (.nupkg) or a public or private NuGet repository.

How To Create A Sitecore Nuget Package

  1. Download NuGet package explorer. http://nuget.codeplex.com/releases/view/59864
  2. Open the sample Sitecore Nuget package. Sitecore.NuGet.Sample

    Open NuGet Package

    Open NuGet Package

    Sitecore NuGet Package

    Sitecore NuGet Package

  3. Edit the metadata for the package using the edit button on the left.
  4. The content folder if for any items (css, c# files, java script etc.) you want to add to your solution. The files will be added to reflect the folder structure here.

    Content Node

    Content Node for adding to the VS solution

  5. The tools folder is where the Powershell and DLL for Sitecore NuGet are contained. You can extend the powershell for pre-install and post-install events.

    Tools Node

    Tools Node

  6. Next we want to serialise Sitecore items to include them in the package. Within the Sitecore content editor navigate to the items you want to serialise and press the Serialize Tree button to serialise the content item and all decendants, do this for all items you want to include in your package.

    Serialise Sitecore Items

    Serialise Sitecore Items

  7. The items are then serialised to the disk. Navigate to your sealisation folder. (C:\inetpub\wwwroot\(ProjectName)\Data\serialization) Copy the serialised items you need into the serialsation folder in NuGet.

    Serialisation

    Serialisation

  8. Save or publish your package to your NuGet repository

Using Your NuGet Package

  1. Install Sitecore Rocks
  2. Create a connection to your Sitecore instance (Make sure the connection is outside the folder Sitecore NuGet can't see the connection in here)

    Sitecore Rocks

    Sitecore Rocks

  3. Add a connection between your project and the Sitecore Rocks connection

    Connect to Sitecore

    Connect to Sitecore

  4. Now you can install your NuGet package directly into your solution and Sitecore instance NuGet Package Installer

    Nuget Package Installer

  5. Powershell and Sitecore rocks will now copy any files into your project and push your serialised items into the master Sitecore database