Setting up Visual Studio Solution for a Sitecore 8.x Website

This blog covers the steps to be done in order to setup a visual studio web project for a Sitecore website.

Let’s go into details.

After a fresh installation of a Sitecore site, here are the folders that get copied to the file system.

  1. Database – contains the database files (.ldf and .mdf)
  2. Data – contains many folders like logs, indexes, license details.
  3. Website – contains all the site related files. IIS would be pointed to this folder.

Before we jump into the steps to create a basic Visual Studio project that can be published into the Sitecore website, Let’s see some folders and files within the “Website” folder.

sitecore website folder content

Folders or files of our interest are

  1. App_config – folder contains all the Sitecore related configurations
  2. Sitecore * – folder(s) contains the files needed to open the Sitecore website
  3. Web.Config – contains few Sitecore specific configurations

Things to keep in mind before we setup the solution is we should never be changing or modifying any of the files directly in our solution, not that it would cause issues, but upgrading or downgrading the Sitecore site would become tedious if we make our application related configurations directly in the files.

A solution for this would be using configuration transforms in the case of web.config and for Sitecore specific configurations (under Sitecore node in the Configuration) we can have our own file and modify anything by Sitecore transformations.

Now, Let’s setup the solution.

To set up a Visual Studio 2015 project for Sitecore MVC:

1. Open Visual Studio 2015 as an Administrator and click File, New, Project… and in the New Project dialog, browse to Templates, Visual C#, Web.. Select ASP.NET Web Application:Picture 4

2. Click OK. In the New ASP.Net Project dialog, create an empty project with folders and references for MVC :

Picture 5

3. In the project folder that Visual Studio created, copy the “global.asax” file from the Website folder of the Sitecore installation, overwriting the “global.asax” file that Visual Studio added when you created the project. The file should only have this content:

        %@Application Language=’C#’ Inherits=”Sitecore.Web.Application” %

4. Replace web.config in the solution with the “web.config” file from Sitecore Website folder.

5. In the NuGet Package Manager in Visual Studio, add these Sitecore packages to your project.

6. In the Solution Explorer in Visual Studio, set the Copy Local property of each DLL reference the NuGet Package Manager added to False.

7. In the Views/Web.config file of your Visual Studio project, add the following Sitecore namespaces to the list of namespaces:

8. Create a folder structure as follows App_config\Include\zz_ and create file “*.config” for example., sitecore.config, to perform any customizations to sitecore configurations.

9. It is a good practice not to change the web.config directly but to create a transformation file and modify it and the same applies to all the files under “App_config” folder of the Sitecore website to make our life easy during an upgrade to a different Sitecore version.

10. To set up the publishing deployment, in the Create Publish Settings dropdown in the Visual Studio toolbar, select.

11. In the Publish Web dialog, in the Publish method field, click File System, and in the Target location field, browse to the Website folder of your Sitecore instance, and then click Publish.