Fixing up Sitecore.Nuget connections


This post aims to document an issue and workaround for something that I spotted when working with Sitecore.NuGet to install Sitecore enabled NuGet packages.

For the uninitiated the following extract explains the idea behind these packages.

Sitecore.NuGet allows NuGet packages to be installed in a Sitecore solution, including Sitecore items.

A Sitecore NuGet package that contains items requires the Sitecore Rocks Hard Rock web service installed on server and that the Visual Project has been connected to the Sitecore installation.

The open source Sitecore.Mvc.Contrib project uses Sitecore.NuGet to package up and install Sitecore content items. In order for these packages to install the Visual Studio project has to be connected to a Sitecore site. In itself that is not a problem, simply right click on the project file in the Visual Studio Solution Explorer, select Sitecore -> Connect to Sitecore Explorer Connection… on the context dialog and connect to a Sitecore website. This will add a connection to the Sitecore Explorer as shown below.

Local IIS Sites Connection

After configuring the project you should be able to install a Sitecore.NuGet package like any other.

PM> install-package sitecore.mvc.contrib

The regular files within the package get installed as expected and then a nasty surprise pops into the package manager console output.

Successfully added 'Sitecore.Mvc.Contrib 1.0.1' to Website.
 install-items : A connection to "sc66contrib (sitecore\admin)" was not found.
 At C:\Websites\sc66contrib\packages\Sitecore.Mvc.Contrib.1.0.1\tools\install.ps1:19 char:3
 + install-items -toolspath $toolsPath -project $project -dte $dte;
 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 + CategoryInfo : NotSpecified: (:) [Install-Items], InvalidOperationException
 + FullyQualifiedErrorId : System.InvalidOperationException,Sitecore.NuGet.Installing.InstallItems

I’m obviously not alone in suffering from this issue:

@KevinObee @TheRocksGuy this. If you’re using local IIS sites in latest rocks it’s busted anyway.

— Kam (@kamsar) August 2, 2013

Why is this happening?

A bit of digging around in the Sitecore.Nuget assembly led me to look at the GetConnectionFolder method

[NotNull]
private string GetConnectionFolder()
{
string path = Path.Combine(Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Sitecore"), "Sitecore.Rocks"), "Connections");
Directory.CreateDirectory(path);
return path;
}

On the file system I found that the AppData\Local\Sitecore\Sitecore.Rocks\Connections directory was empty. My connection file was located in the Local IIS Sites sub-folder.

Relocated Connection So the quick fix then is to move the Sitecore Rocks connection out of Local IIS Sites up into the Connections folder. You can either do this using Windows Explorer or use the Sitecore Explorer inside Visual Studio to drag and drop the connection to the right location. With that done my package now installs as expected and the Sitecore items that it contains get installed into the Sitecore Content Tree.

PM> install-package Sitecore.Mvc.Contrib
Attempting to resolve dependency 'Microsoft.AspNet.Mvc (≥ 3.0.20105.1)'.
Attempting to resolve dependency 'Microsoft.AspNet.WebPages (≥ 1.0.20105.408)'.
Attempting to resolve dependency 'Microsoft.Web.Infrastructure (≥ 1.0.0.0)'.
Attempting to resolve dependency 'Microsoft.AspNet.Razor (≥ 1.0.20105.408)'.
Installing 'Sitecore.Mvc.Contrib 1.0.1'.
You are downloading Sitecore.Mvc.Contrib from Mike Edwards, Kern Herskind, Kevin Buckley, Kevin Obee, Stephen Pope, the license agreement to which is available at http://www.apache.org/licenses/LICENSE-2.0. Check the package for additional dependencies, which may come with their own license agreement(s). Your use of the package and dependencies constitutes your acceptance of their license agreements. If you do not accept the license agreement(s), then delete the relevant components from your device.
Successfully installed 'Sitecore.Mvc.Contrib 1.0.1'.
Adding 'Sitecore.Mvc.Contrib 1.0.1' to Website.
Successfully added 'Sitecore.Mvc.Contrib 1.0.1' to Website.
PM>

Distributing software via a package manager has become the norm over the last couple of years. In the .NET environment we have NuGet packages for pulling in software libraries as dependencies of our projects. It is very good news to see that Sitecore now has the ability to package both files and content items using this de facto standard for software distribution. This is a key to enabling successful build and deployment automation processes such as  continuous integration and delivery pipelines.

Advertisements

One thought on “Fixing up Sitecore.Nuget connections

  1. Pingback: Code Generation using Sitecore Rocks and Visual Studio

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s