1

For Unicorn serialization currently i have given path like

<targetDataStore physicalRootPath="C:\SitecoreProjects\Unicorn1\src\Project\Unicorn_Test\serialization" 

However its absolute source path in my machine and working fine for me. Since we are working in a team, how can i make this to relative path so that all team members can check out this from source control work without any issues while reserialize and sync?

2 Answers 2

3

You can do this by using a variable that gets set in a developer only config. I would normally setup the targetDataStore like this in my unicorn config:

<targetDataStore physicalRootPath="$(sourceFolder)\$(layer)\$(module)\serialization\Website" />

Then in my website project, I have a z.DevSettings.config file, where I specify the value for the $(sourceFolder) variable:

<?xml version="1.0"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
    <sitecore>
        <sc.variable name="sourceFolder" value="C:\Projects\MyProject\src" />
    </sitecore>
</configuration>

That file is not committed to source control, each developer would create a version of that so that the source folder can be set based on your local machine setup. We don't commit it, because then it will not affect anyone else.

0
0

Explanation

Relative - to what? That is the issue here. Your solution files live in your solution folder, likely under GIT control or some other form of source control.

When Unicorn executes, it executes in your Web Context (IIS folder) and knows nothing about the solution that was published to it.

No relative path would work here, ~/ is pointing to the IIS "Website" folder.

Another approach

An interesting - although untested by me - solution to this was also presented on the Unicorn Issues area.

Question: how can I specify a solution relative path for "targetDataStore" configuration property

It basically introduces a $(solutionFolder) variable that can then be used in the configuration of <targetDataStore>.

I've not tried it myself (and a part of me thinks this is maybe overkill), but wanted to offer up an alternative answer to Richards answer above (which is the approach I use as well).

It involves a T4 template and a config transformation.

T4

<#@ template debug="false" hostspecific="true" language="C#" #><# /* hostspecific must be set to "true" in order to access Visual Studio project properties. */ #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Text" #>
<#@ output extension=".config" #>
<#@ assembly name="EnvDTE" #><# /* This assembly provides access to Visual Studio project properties. */ #>
<#
    var serviceProvider = this.Host as IServiceProvider;
    var dte = serviceProvider.GetService(typeof(EnvDTE.DTE)) as EnvDTE.DTE;
    var solutionDirectory = System.IO.Path.GetDirectoryName(dte.Solution.FullName);
#>

Transform

<?xml version="1.0" encoding="utf-8"?>

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
    <sitecore>
      <sc.variable name="solutionFolder" value="<#= solutionDirectory #>" 
        xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
    </sitecore>
</configuration>

And then using it in Unicorn

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.