SitecoreUnicorn / Unicorn

A Sitecore utility designed to simplify deployment of Sitecore items across environments automatically
MIT License
269 stars 116 forks source link

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

Closed Tharnadar closed 6 years ago

Tharnadar commented 6 years ago

Hi everyone, I would like to specify a solution relative path (eg: $(SolutionDir)\Unicorn\$(configurationName) ) for the configuration property targetDataStore in order to serialize items in a project/folder inside my solution (not in the IIS folder). We cannot use an absolute path, because we would like to have different items in different branches.

Is it possible somehow?

Thank you

kamsar commented 6 years ago

Unicorn runs at a Sitecore level and is thus entirely unaware of visual studio and any of its conventions. Syncing also usually takes place on deployed systems where visual studio artifacts are not present even if the config were somehow keyed off VS. Take a look at how Habitat specifies a system level root path for serialized items in a vars file.

On Mon, Jan 22, 2018, 9:06 AM Tharnadar notifications@github.com wrote:

Hi everyone, I would like to specify a solution relative path (eg: $(SolutionDir)\Unicorn$(configurationName) ) for the configuration property targetDataStore in order to serialize items in a project/folder inside my solution (not in the IIS folder). We cannot use an absolute path, because we would like to have different items in different branches.

Is it possible somehow?

Thank you

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/kamsar/Unicorn/issues/275, or mute the thread https://github.com/notifications/unsubscribe-auth/AAGU_fH_IIWhOU_jyZXlX4eaaWRbu0Ktks5tNMAvgaJpZM4RoTwK .

Tharnadar commented 6 years ago

Thank you Kasmar.

For those who are interested in a solution (or workaround), we have defined a sc.variable named solutionFolder, and with a custom T4 template, we have created a web.config transformation that replace the sc.variable value with the actual solution directory path.

<#@ 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);
#>
<?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>

Finally we've changed the targetDataSource as below

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