Habitat project Setup

Recently, I have started working on Habitat setup and I am new to Helix guideline and Habitat project. Below links, I have used to learn more about Helix.

Helix Document – http://helix.sitecore.net/

Habitat Project – https://github.com/Sitecore/Habitat

Habitat Setup Wiki – https://github.com/Sitecore/Habitat

After this, I have started to setup Habitat project in my local system. During the setup of habitat project, I have faced some of the challenges, which I though it may be helpful to you as well while doing habitat setup.

Error occurs while setup Habitat Project.

Error – 1

Sync.ps1 cannot be loaded because running scripts is disabled on this system.

PS [HabitatProjectFolder]\scripts\Unicorn> .\Sync.ps1 -secret 749CABBC85EAD20CE55E2C6066FdBE3f5D2115d96s8A8B24DB6ED1FD60613086 -url http://habitat.dev.local/unicorn.aspx
.\Sync.ps1 : File C:\Sitecore\Sitecore-Habitat\Habitat-master\scripts\Unicorn\Sync.ps1 cannot be loaded because running
scripts is disabled on this system. For more information, see about_Execution_Policies at
At line:1 char:1
+ .\Sync.ps1 -secret 749CABBC85EAD20CE55E2C6066F1BE375D2115696C8A8B24DB ...
+ ~~~~~~~~~~
    + CategoryInfo          : SecurityError: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess

For Continues execution of script, we need to set windows powershell execution policies by executing below command on Powershell window.

PS [HabitatProjectFolder]\scripts\Unicorn> Set-ExecutionPolicy Unrestricted

Error – 2

Invoke-WebRequest :       The resource cannot be found.

PS [HabitatProjectFolder]\scripts\Unicorn> .\Sync.ps1 -secret 749CABBC85EAD20CE55E2C6066F1BE375D2115696C8A8B24DB6ED1FD60613086 -url http://habitat.dev.local/unicorn.aspx
Sync-Unicorn: Preparing authorization for http://habitat.dev.local/unicorn.aspx?verb=Sync&configuration=
Invoke-WebRequest : 
        The resource cannot be found.

Please make sure that, Your Sitecore website(http://habitat.dev.local) which you have link with habitat setup is up and running.

Error – 3

[08:57:43] Starting ’05-Sync-Unicorn’… –  Execution stuck

I have dig “[HabitatProjectFolder]/gulpfile.js” file in which, it was triggered “[HabitatProjectFolder]/scripts/Unicorn/Unicorn.psm1 and “[HabitatProjectFolder]/scripts/Unicorn/sync.psm1” files. All the commands are written on this file. I have commented out “$ErrorActionPreference = ‘Stop’” from both of the files by adding “#” before the line (Available on first line of files).

Now, I am able to see actual error in Task Runner Explorer of visual studio 2015.

Error – 4

In my case, I am getting Could not load file or assembly file MicroCHAP.dll or one of its dependencies”

I have unblock following files in the code repository, you can do it by right click on each one of them and click on “properties” – “General” – “Unblock”:

  • Habitat-master\scripts\Unicorn\MicroCHAP.dll
  • Habitat-master\scripts\Unicorn\Sync.ps1
  • Habitat-master\scripts\Unicorn\Unicorn.psm1.

Error – 5

“Rainbow – SERIALIZATION FOLDER PATH MAX LENGTH” – File Path Length cross 150 char length.

  • Max Length is 150 character, if your habitat project folder structure path takes more the 150 char then it gives error.

How to get sitecore unused media item using SQL Query

As we all know, Sitecore use link database to store referrers of item and using those referrers, we can identify unused media item.

Below are the steps which we need to execute to get unused media item.

Step 1: 

Identify database in which all the media item referrers are stored. For that, we need to check below configuration node in web.config/Sitecore.config file (default sitecore use core database to store referrers).

<LinkDatabase type="Sitecore.Data.$(database).$(database)LinkDatabase, Sitecore.Kernel">

<param connectionStringName="core"/>


Step 2:

Below SQL query to get unused image/file item list.


Replace below tokens as per requirement.

#MediaRootItemID#: This token use to provide root media item (result of this query return all the unused descendant media items of given root media item).

#TemplateID#: if user exclude some of the items, which was created using specific template then replace those template ID in this token.

WITH descendantsItem AS(
FROM [Master].[dbo].Items
WHERE ID = '#MediaRootItemID#'
SELECT i.ID,i.TemplateID
FROM [Master].[dbo].Items i
INNER JOIN descendantsItem di
ON di.ID = i.ParentID ),LinksItem AS(
FROM [Core].[DBO].Links
WHERE TargetItemID in (
FROM descendantsItem
where descendantsItem.TemplateID != '{FE5DD826-48C6-436D-B87A-7C4210C7413B}'))
FROM descendantsItem
WHERE descendantsItem.ID NOT IN (
FROM LinksItem) AND TemplateID != '{FE5DD826-48C6-436D-B87A-7C4210C7413B}'


Sitecore Item Operations Tool

I am really very excited to write this post because this post related to my first tool that have contributed in Sitecore Market Place (https://marketplace.sitecore.net). Finally they have approved and published the “Item Operations Tool” module and it is available on Sitecore marketplace.

This tool is use for doing some basic operations on item. So have given name as “Item Operations Tool”. Mainly this tool use for comparison of item with live item, count sub items and expands all the dependents of item

Download installation package from below link.



Step -1: Download installation package from above link.

Step -2: installed downloaded package into local Sitecore.

Step -3: add following entry into Commands.config

<command name="item:ItemComparer" type="CustomCommands.ItemComparer,CustomCommands"/>

<command name="item:countSubItems" type="CustomCommands.CountSubItems,CustomCommands" />

<command name="item:ExpandDescendants" type="CustomCommands.ExpandDescendants,CustomCommands" />

Step -4: Restart Sitecore instance.

When you open Sitecore instance you can see new menu item in side version –> Item in below image.

Sitecore Item Operation Tool

Item Operations

Item Comparer

I am going to provide a tool in Content Editor that will allow users to compare contents of master and web databases. (Sitecore Ribbon: Version -> Item -> Item Compare)

– This will show all fields of both databases to compare.

– The default selected item and language should be compared.

Once you click on Item Compare button.

Compare Item

This will show all fields of both databases to compare.


The differences are highlighted in blue and red.

Blue: Apply on field value to highlight difference of field value.

Red: Apply on field title to identify that the field value is different form live field value).

Count Subitems

You can Count the number of sub items (all descendant sub items) of particular item. To do so, please follow below steps:

  1. Navigate to particular item of which you want to get sub items count.

Click on “Count SubItems” from ribbon as shown in below image.

count subitem in sitecore

Expand subitems

You can expand all sub items (all descendant sub items) of particular item. To do so, please follow below steps:

  1. Navigate to particular item of which you want to expand SubItems.

Click on “Expand SubItems” from ribbon as shown in below image to expand sub items (all descendant sub items) of particular item.

Expand Subitem