If you are using Unicorn to share Sitecore items among developers / or for deployment, you have probably came across some trouble with dependencies between modules / projects.

For example if you are following Helix guidelines, your Feature module Sitecore items are dependent on Foundation module Sitecore items. Take a look on Helix documentation for a very nice example of this kind of dependency.

Another example would be to have interface templates in one project (on Feature level) and their “implementation” as folder type template in another project (on Project level).

Issues arise when these dependencies between modules are omitted or forgotten and you are syncing all items with Unicorn. This could fail when you sync first dependent templates from Project level before templates from Feature level.

To overcome these issues, you need to use below notation in your Unicorn config file:

 dependencies="Foundation.Serialization,Foundation.Indexing"

This notation needs to be used in modules that are dependent on other modules.

So if you need module Feature.Navigation to be dependent on Foundation.Serialization or Foundation.Indexing modules you would make it like this:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
    <unicorn>
    <configurations>
        <configuration name="Feature.Navigation" description="Feature Navigation" dependencies="Foundation.Serialization,Foundation.Indexing" patch:after="configuration[@name='Foundation.Serialization']">
        <targetDataStore physicalRootPath="$(sourceFolder)\feature\navigation\serialization" type="Rainbow.Storage.SerializationFileSystemDataStore, Rainbow" useDataCache="false" singleInstance="true" />
        <predicate type="Unicorn.Predicates.SerializationPresetPredicate, Unicorn" singleInstance="true">
            <include name="Feature.Navigation.Templates" database="master" path="/sitecore/templates/Feature/Navigation" />
            <include name="Feature.Navigation.Renderings" database="master" path="/sitecore/layout/renderings/Feature/Navigation" />
        </predicate>
        <roleDataStore type="Unicorn.Roles.Data.ReverseHierarchyRoleDataStore, Unicorn.Roles" physicalRootPath="$(sourceFolder)\feature\navigation\roles" singleInstance="true"/>
        <rolePredicate type="Unicorn.Roles.RolePredicates.ConfigurationRolePredicate, Unicorn.Roles" singleInstance="true">
            <include domain="modules" pattern="^Feature Navigation .*$" />
        </rolePredicate>
        </configuration>
    </configurations>
    </unicorn>
</sitecore>
</configuration> 

Unicorn will automatically determine order of projects / modules (or in other words module dependencies) based on this configuration therefore Foundation.Serialization and Foundation.Indexing modules will be synced first and then Feature.Navigation.

You can also use wildcards and set dependencies this way:

dependencies=”Foundation.*”

which will automatically push current module to be synced after all Foundation one.

You can see more examples on how to set dependencies in Unicorn in this example config file on Unicorn’s GitHub.

Sample configuration for my above example was taken from Helix documentation.

Happy syncing in right order πŸ™‚