Issues / resolution setting up Unicorn for Sitecore 10.1.1 Helix-based project

Although a Helix-based solution is setup based on Helix conventions, there is a possibility that every developer interprets it in a different way and as a result, could end up setting the sln in a different or wrong way. Here is where tools/plugins help. In the following blog article, I'm setting up a solution manually and have documented all the issues and solutions faced. In my next blog article, I'm going to use Anders Laub plugin to setup the same sln and see if it helps streamline the process. Then, I plan to move over to using HPP-based convention.

Note that even in this process, I setup a working sln but then there are a few issues:

1. My serialization data store location is not specific to the feature but I set it up somewhere outside the Helix file structure

2. No naming standards generally, I follow "my way free way approach"

3. Most importantly, I created folder names / the whole structure manually

4. You could end up adding Feature-based config code in Foundation layer  or vice-versa

But, only if you follow this approach, you will appreciate the beauty of plugins and boiler-plate code. 

First basic step that could save a lot of time; In Visual Studio, ensure that web.config for all projects/ layers have this setting in order to overcome unnecessary DLL version errors while publishing to the web application or the destination folder:

Build Action - None

Copy to Output Directory - Do not copy

Ensure to rename Unicorn.DataProvider.10.1.config.disabled to a customized name, in my case, I made it CustomSitecoreCommand.Unicorn.Configs.config and added it under Unicorn\zzz before  publishing to the target or the web application folder:

Note that the example config files will get added to your foundation project automatically when you restore the Unicorn nuget package in Visual Studio. I used 2019 version in this case. 

Also note that in the above screen shot, the configuration settings are specific to feature rather than relevant to the foundation.

Next, Ensure to (re)name Unicorn.SharedSecret.config to Unicorn.zSharedSecret.config and have a valid shared secret value. I picked the shared secret value from the habitat project config. Chuck this file too under Unicorn\zzz folder.


Note that if you already used Unicorn.SharedSecret.config and had published the same to the target or the web app folder, ensure to delete the concerned file from the target folder since only Unicorn.zSharedSecret.config must be present in the target folder as per this Stackoverflow issue / solution

After setting up the above files, I could see the Unicorn page:


Note that at this point, if you run the Sync-Unicorn task in the Visual Studio Task runner explorer, you could still get this error if you haven't yet configured the datastore for sync:

Sync-Unicorn: Executing Sync...

Sync Unicorn

ERROR: Configuration(s) requested were not defined. (System.ArgumentException)<div class="stacktrace">at Unicorn.ControlPanel.Pipelines.UnicornControlPanelRequest.SyncVerb.ResolveConfigurations()

<br />   at Unicorn.ControlPanel.Pipelines.UnicornControlPanelRequest.SyncVerb.Process(IProgressStatus progress, ILogger additionalLogger)

<br />   at Unicorn.ControlPanel.Pipelines.UnicornControlPanelRequest.SyncVerb.<>c__DisplayClass3_0.<CreateResponse>b__0(IProgressStatus progress)

<br />   at Unicorn.ControlPanel.Responses.WebConsoleResponse.ProcessInternal(IProgressStatus progress)

<br />   at Kamsar.WebConsole.TextWebConsole.Render(Action`1 processAction)

<br />   at Unicorn.ControlPanel.Responses.WebConsoleResponse.Execute(HttpResponseBase response)</div>

****ERROR OCCURRED****

Error: Unicorn Sync to <web app root>/unicorn.aspx?verb=Sync&configuration=&skipTransparentConfigs=0 returned an 

Error: error. See the preceding log for details.

At <dev folder>\scripts\Unicorn\Unicorn.psm1:66 char:3

+         throw "Unicorn $Verb to $url returned an error. See the prece ...

+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : OperationStopped: (Unicorn Sync to...og for details.:String) [], RuntimeException

    + FullyQualifiedErrorId : Unicorn Sync to <web app root>/unicorn.aspx?verb=Sync&configuration=&skipTra 

   nsparentConfigs=0 returned an error. See the preceding log for details.



Next, ensure to add Unicorn.UI.IdentityServer.config.disabled file to Unicorn\zzz and give it a custom name, in my case, I named it - CustomSitecoreCommand.UI.IdentityServer.config

Note that without this patch file, Unicorn wouldn't be able to login since identity server wouldn't authorize Unicorn. 

So, after you setup the above patch, access the unicorn url, provide Sitecore admin credentials and you should be able to see the Unicorn serialization page:


Scroll down and perform initial serialization for the project. Without performing initial serialization for the (Feature) project, you will get the following error in the task runner explorer if you run the Sync-Unicorn task:

Starting 'Sync-Unicorn'...
Sync-Unicorn: Executing Sync...
Sync Unicorn
<Feature name> is being synced.
Unable to resolve serialized item for included root path core:/sitecore/content/Documents and settings/All users/Start menu/Right. The item does not exist in Serialization File System Data Store. It has been skipped. Perhaps you need to perform an initial 
serialization from the control panel?
<Feature name> had no root paths included to sync. If you&#39;re only syncing roles and/or users, this is expected. Otherwise it indicates that your predicate has no included items and you need to add some.
<Feature name> sync complete: 0 items evaluated, 0 items modified (0 added, 0 updated, 0 recycled) in 60ms (~61.00ms/item).
Completed in 127ms.
****ERROR OCCURRED****
Error: Unicorn Sync to <web app root>/unicorn.aspx?verb=Sync&configuration=&skipTransparentConfigs=0 returned an 
Error: error. See the preceding log for details.
At <dev path>\scripts\Unicorn\Unicorn.psm1:66 char:3
+         throw "Unicorn $Verb to $url returned an error. See the prece ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (Unicorn Sync to...og for details.:String) [], RuntimeException
    + FullyQualifiedErrorId : Unicorn Sync to <web app root>/unicorn.aspx?verb=Sync&configuration=&skipTra 
   nsparentConfigs=0 returned an error. See the preceding log for details.


Since I decided to serialize all Sitecore items under /sitecore/content/Documents and settings/All users/Start menu/Right in the core db, I can see the following end-result:



Note that the files are serialized based on the physical path provided in  CustomSitecoreCommand.Unicorn.Configs.config 

Also, note that it would have been better had I created a folder in the Sitecore tree and pointed to it rather than serializing all the OOTB items.

Anyway, If you now go back to the Control panel, you must now see an option to sync back the serialized items to the Sitecore instance:


Switch to showconfig.aspx to check how the patches are applied:

Serialization Datastore:


Shared secret:

References: 

https://www.youtube.com/watch?v=d3g0QMWSuGg&t=1534s

https://navansitecorenotes.blogspot.com/2021/07/npm-gulp-not-recognized-error.html

Comments