Sitecore Helix and Habitat – creating a new module/project
Helix is a set of overall design principles and conventions for Sitecore development. Helix gives developers some architectural guidelines that have emerged out of experience from past Sitecore implementations
The core focus of Helix is the separation of functionality into modules – a conceptual grouping of all assets related to a single business requirement and their organization into layers. This organization is beneficial because it reduces dependency between modules, minimizes side effects and additional efforts in later iterations.
Helix defines some rules on how to organize the filesystem and items in the content tree. When we follow these rules, we can be sure that other developers can easily navigate the solution we built.
Habitat is nothing but a way on how to implement Sitecore solution based on Helix design principles. Habitat is a real Sitecore project, built using the overall design principles and conventions provided by Helix.
Habitat solution for Sitecore v9 is available on Github, and Habitat demo site is also available online for reference. Sitecore Habitat solution can be set up by following the steps which are explained in many articles and videos available online.
This article describes the steps to add a new module/project in Sitecore while following Helix principles and using Habitat solution.
Creating a new module/project
Here we are taking an example of creating a new project by the name Ports in the Sitecore Habitat solution project section. Any module in Feature and Foundation can be created in the same way:
1. Create a folder structure:
a. Open windows file explorer and navigate to the path for existing Sitecore solution
b. Inside the above path, create the following folder structure
2. Create a new project in Visual Studio:
Open Visual Studio 2017 in administrative mode
a. Open the Sitecore Habitat solution from the location
b. Create a solution folder by the name “ports” inside “project” section
c. Create a project in the newly created “ports” folder:
i. Right click “ports”, add à new project
ii. Use the template “ASP.NET web application”
iii. Select the project location inside the file system as below C:VSTSAdvaiyaSitecoreCodeAdvaiyasrcProjectPorts
iv. Name the project as “code” to maintain the correct folder structure. We will rename it to project in the next steps.
v. Click next, now select “Empty” project template and check the “MVC” checkbox
vi. Click “OK”
3. Setting properties to the new project:
a. Rename the project to Sitecore.Ports.Website
b. Go to the project properties and set the assembly name and namespace to Sitecore.Ports.Website
c. Update the project framework to “.NET Framework 4.6.2”
d. Delete the folders from Project App_Data, App_Start, and Global.asax
e. Go to properties “web.config” file and “/views/web.config” files, and set “Build Action” property, to “None”. By setting this property you will not publish these files with the project.
4. Add configuration files:
a. Create the following folder structure in the Visual Studio under Sitecore.Ports.Website as below:
/App_Config/Include/Project and /App_ConfigEnvironment/Project
5. Create a publish profile:
a) Copy the”/Properties/PublishProfiles” folder from the other project.
b) Paste it at the same place in the new project Sitecore.Ports.Website project.
6. Copy required assemblies from another project:
a) Unload the project, edit the project file.
b) Unload any other project, edit the project file.
c) Compare both project files and add assemblies in the new project from another project.
d) Comment target location at the end of the project file, comparing with another project.
e) Reload the projects.
f) Re-Build the new project, and it will add all the required assembly references now.
7. Create required folders in CMS
a) Go to Sitecore CMS, enter login details and open content editor
b) Create required project folder inside:
vi. Placeholder settings
8. Check configurations and sync:
a) Open Unicorn.aspx page
b) Check if all configurations are done for the newly created project/module
c) If not, then check for errors and resolve them one by one
d) Re-serialize newly created project/module
e) Sync project/module
The newly created project or module is ready. If you need to create a new project for a website in multisite solution, then IIS binding and host file entry for the new website has to be done. If you need any assistance for Sitecore implementation or in the creation of a project/module our team of experts can help you.