Skip to content
Sitecore with gulp

Take out Gulp from the Helix Solution

Posted in :

rbatallas

One of the critical things when we do an upgrade to our Sitecore Instance is to upgrade the code and the helix structure in the solution.

So, I will describe the primary topics that everyone has to keep in mind in the upgrade process:

  • Remove Gulp files.
  • Add a web wrapper project for deploying the solution to the website on our local machine.

Remove Gulp Files

When we have an old solution using gulp sometimes is complicated because we need to use an old node js version. So, to remove gulp files is just to delete them from the solution, which is not a big deal right?

Let’s do the next step, add the wrapper project.

Wrapper Project

This project is another web project in our solution that follows the Helix principles.

The first step in our solution is to add a new solution folder named Website, and of course, we need to do the same in the file systems structure.

Add an empty web project to the solution, and then we need to configure the following references:

NOTE: About the Sitecore references, you must match the Sitecore version that you are working with the package version.

The magic comes with the “RichardSzalay.Helix.Publish.WebRoot” package, this helps you to deploy all the project’s dll, views, images, styles, and scripts from each project in the solution.

The next step is to add the following file “Directory.build.props” with the following content.

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <PropertyGroup>
    <PublishProfile>Local</PublishProfile>
    <LangVersion>latestMajor</LangVersion>
  </PropertyGroup>

  <!-- As long as your modules follow these patterns, their content will automatically be included in the publish -->
  <ItemGroup>
    <ProjectReference Include="..\..\Foundation\*\code\*.csproj" />
    <ProjectReference Include="..\..\Feature\*\code\*.csproj" />
    <ProjectReference Include="..\..\Project\*\code\*.csproj" />
  </ItemGroup>
 
</Project>

With this file, we automatically add all the references to all projects in the solution.

The next one is the wpp.targets file, this one should be named like the project, for example, “Hyland.Website.wpp.targets” and have to have the following content:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

    <ItemGroup>
        <!-- 
    Exclude Sitecore assemblies from publish to reduce data transfer and file size. 
    https://github.com/richardszalay/helix-publishing-pipeline#excluding-sitecore-assemblies
    -->
        <SitecoreAssembliesToExclude Include="@(SitecoreAssemblies)" />

        <!-- no longer required with Sitecore.Assmblies.Platform NuGet package
  <SitecoreAssemblyListsToExclude Include="AssemblyLists\*.csv" /> -->

    </ItemGroup>

    <PropertyGroup>
        <!-- 
    Set to false if you don't want it to publish after each build
    https://github.com/richardszalay/helix-publishing-pipeline#publishing-on-build
    -->
        <EnableAutoPublish>false</EnableAutoPublish>

        <AutoPublish Condition="'$(AutoPublish)' == '' and '$(EnableAutoPublish)' == 'true' and '$(Configuration)' == 'Debug' and '$(BuildingInsideVisualStudio)' == 'true' and '$(PublishProfile)' != ''">true</AutoPublish>

        <AutoPublishDependsOn Condition="'$(AutoPublish)' == 'true'">
            $(AutoPublishDependsOn);
            WebPublish
        </AutoPublishDependsOn>
    </PropertyGroup>

    <Target Name="AutoPublish" AfterTargets="Build" DependsOnTargets="$(AutoPublishDependsOn)">
    </Target>

    <UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(MSBuildToolsVersion)\Web\Microsoft.Web.Publishing.Tasks.dll" />
    <Target Name="ApplyTransform">
        <ItemGroup>
            <Transform Include="$(TransformFile)" />

            <ConfigsToTransform Include="$(FileToTransform)" Condition="Exists(@(Transform))">
                <TransformPath>%(Transform.Identity)</TransformPath>
            </ConfigsToTransform>
        </ItemGroup>
        <Message Text="@(ConfigsToTransform)"></Message>
        <Message Text="@(Transform)"></Message>

        <TransformXml Source="$(WebConfigToTransform)\%(ConfigsToTransform.Identity)"
                      Transform="%(ConfigsToTransform.TransformPath)"
                      Destination="$(WebConfigToTransform)\%(ConfigsToTransform.Identity)"
                      Condition="Exists(@(Transform))"/>
    </Target>

</Project>

With this file, we can exclude the dlls that are not required to be published to the Sitecore instance.

and finally what you need to do is to create a publish profile in this project to deploy all the stuff to the Sitecore instance.

NOTE: Remember not to deploy the “web.config” file if is not required.

Should look like this:

And that’s all! for more information about it, please review all about the latest helix project structure.

Hope this article was helpful in any way. Happy coding! 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *