Unicorn for Sitecore Setting up Separate Core/Master Database Serialization

After getting the Unicorn sync to work I wanted to have separate folders for the Core and Master database items. It will keep things organized much better that way IMHO. After researching an asking around in Slack I came up with the following solution.

First  based on the Unicorn.Configs.Default.example I created two new configs. Unicorn.Configs.Core.config and Unicorn.Configs.Master.config.

coremasterconfig

In each file I changed the configuration name and description. Also it is very important that you add an entry for the physicalRootPath. This will override the default path.

This is what I did for the Core database. You will notice that the path ends in \Core.

 <configuration name="SitecoreTestSiteCore" description="This is my Sitecore Test Site. I am testing Unicorn and syncing CORE only.">
 <targetDataStore physicalRootPath="C:\Projects\SitecoreTestSite\src\WebApplication1\WebApplication1\App_Data\Unicorn\Serilization\Core" type="Rainbow.Storage.SerializationFileSystemDataStore, Rainbow" useDataCache="false" singleInstance="true" />

This is what I did for the Master database. You will notice that the path ends in \Master.

 <configuration name="SitecoreTestSiteMaster" description="This is my Sitecore Test Site. I am testing Unicorn and syncing Master only.">
 <targetDataStore physicalRootPath="C:\Projects\SitecoreTestSite\src\WebApplication1\WebApplication1\App_Data\Unicorn\Serilization\Master" type="Rainbow.Storage.SerializationFileSystemDataStore, Rainbow" useDataCache="false" singleInstance="true" />

After Initialization I did a sync. Look it is a cool looking unicorn.

unicorn

Now I have two separate directories for Core and Master files.

coremasterdirectory

Let me know if you have any questions.

Unicorn for Sitecore and Version Control First Time Setup

After I got #Unicorn for #Sitecore setup for the first time I noticed the folders and yml files were created in my sites data folder. I want those files as part of my project and source controlled similar to TDS. So doing some research I found this setting in the Unicorn.config folder.

<targetDataStore
physicalRootPath=$(dataFolder)\Unicorn\$(configurationName)
useDataCache=false
type=Rainbow.Storage.SerializationFileSystemDataStore, Rainbow
singleInstance=true/>

I changed to my local folder in my project. I created two new folders under App_Data (Unicorn\Serialization).

<targetDataStore
physicalRootPath=C:\Projects\SitecoreTestSite\src\WebApplication1\WebApplication1\App_Data\Unicorn\Serilization
useDataCache=false
type=Rainbow.Storage.SerializationFileSystemDataStore, Rainbow
singleInstance=true/>

*Please note there is a Unicorn.CustomSerializationFolder.config.example that you can also change this setting in. Just remove the .example to use it.

When I went to [site]/unicorn.aspx I received the following error. If you receive this error either change the path to a smaller length or in my case I changed the value in App_Config\Include\Rainbow.config.

I changed this line:

<setting name=”Rainbow.SFS.SerializationFolderPathMaxLength” value=”103″ />

To

<setting name=”Rainbow.SFS.SerializationFolderPathMaxLength” value=”105″ />

Now after going back in to the Unicorn Control Panel I was able run an Initial Serialization. I had to do this since the folder path changed.

Then Sync Selected.

SitecoreTestSite sync complete: 1767 items evaluated, 0 items modified (0 added, 0 updated, 0 recycled) in 6331ms (~3.6ms/item).

Now back in my solution I show hidden files and folders and there are my files. I can then include them in my project.


So now you can make the files part of any source control sytem you are using. It is worth mentioning that there are other methods you can use like Sitecore Courier and Sitecore Ship. Also since projects are sometimes setup different locally for developers using something like slowcheetah might be a good idea to have your own development configuration for the Unicorn.config and Rainbow.config.

Update. In your publish settings I recommend checking the box that says Exclude files from the App_Data folder. You probably don’t want to publish those files.

localdeploy

Now I need to figure out how to sync someone else’s changes. I suspect it might be using the Publish Unicorn and Replace Unicorn from Server options.

Unicorn for Sitecore Setting up for the First Time

Most of my #Sitecore projects have been spent using packages and TDS to get Sitecore items updated. I was told recently about another tool and decided with a cool name like Unicorn I had to try it out. I like the name being that in my house at one point my kids believed Unicorns were real. I told them they are real, but Noah forgot to take them on the Arc with him. Anyhow let’s get started.

I started with following the documentation. It was straightforward.

https://github.com/kamsar/Unicorn/blob/master/README.md

How to get the Nuget package.

https://www.nuget.org/packages/Unicorn/

Included in the installation is a sample config file. You can copy it and change the extension from sample to config. I just kept it simple and named mine Unicorn.Configs.Default.config.

In the config file under the predicate section you can add paths here. You can see ones already defined with include tags. I just changed the stuff highlighted in yellow.

<configuration name=”SitecoreTestSite” description=”This is my Sitecore Test Site. I am testing Unicorn.“>

    <predicate type=”Unicorn.Predicates.SerializationPresetPredicate, Unicorn” singleInstance=”true”>

        <!–

            PREDICATE

                The predicate controls what items are included in the configuration.

                Each include can also exclude specific subitems in various ways. For a reference of the most current predicate grammar, consult the tests here:

                https://github.com/kamsar/Unicorn/blob/master/src/Unicorn.Tests/Predicates/TestConfiguration.xml

                NOTE: after changing what is included or excluded, you should reserialize all items, or at least the added items for additions.

                NOTE: the “name” attribute controls the folder name the items will go into. If unspecified, the last path segment is used. Names must be unique across the configuration.

                NOTE: You cannot use excludes with Transparent Sync. See https://github.com/kamsar/Unicorn/wiki/The-Transparent-Sync-Guide

        –>

                <include name=”Layouts” database=”master” path=”/sitecore/layout/Layouts/ ” />

                <include name=”Templates” database=”master” path=”/sitecore/templates/” />

                <include database=”master” path=”/sitecore/system/Languages” />

                <include database=”master” path=”/sitecore/system/Tasks”>

                    <exclude path=”Schedules” />

                </include>

                <include database=”master” path=”/sitecore/system/Workflows” />

                <include database=”master” path=”/sitecore/system/Settings” />

                <include database=”master” path=”/sitecore/content/”></include>

            </predicate>

After publishing your site just go to http://[Your Site Goes Here]/unicorn.aspx. You will see a message about not having any valid serialized items and to do an initial serilization.

No problem. The developers included a button to click to do the initial serialization.

After clicking the button the following came up.

Now I get the following option.

Clicking on the checkbox you get a Sync Selected and Reserialize Selected option.

After clicking on Sync Selected. An awesome Unicorn appears with messages below.

Now in my data directory I can see Unicorn created folders and within those folders are yml files (more about these types of files https://rhnh.net/2011/01/31/yaml-tutorial/).

On a side note. I installed a Unicorn utility that caused a dll version issue. So I had to copy back some files to get it to work again. So if you run into this issue make sure all the file versions are the latest even the MicroCHAP dll.

So that is it for now. As I use this more on projects I will blog about it some more. Let me know if you have any questions. Thanks.