PART I: Sitecore & MVC: Project setup

The last couple of months i have been busy researching and developing with Sitecore and MVC. During development I had some challenges to get it to work properly. In a series of posts I will explain some solutions for the challenges you will face after taking certain decisions.

Let’s begin with setting up a new Solution for our Sitecore MVC project.

Setup our Sitecore MVC Visual Studio solution

First we take the following steps to setup out new project:

  1. Install a new Sitecore instance
  2. Create a new Solution/Project in Visual Studio
  3. Select ASP.NET Web Application as your project type
  4. Select the “Empty” template
  5. Check the “MVC” checkbox under the section “Add folders and core references for”
  6. Click OK

In the next few steps we copy some necessary files to your projects:

  1. On the same level as your solution file (.sln) create a new folder external.
  2. Select the files: Sitecore.Kernel.dll and Sitecore.Mvc.dll from the Sitecore instance to your new folder.
  3. Copy the Web.config from the Sitecore Instance and we paste it into our own project (just overwrite the existing).

Almost ready. Create a publishing profile a make our publish target location is the root of the Sitecore instance and “Delete all existing files prior to publish” is NOT checked. Let’s click the “Publish” button and check if your Sitecore instance is still working properly.

We may get some errors about non matching assembly versions related to MVC and Illegal routing, let’s fix them. Since we create our project with an empty MVC project we have already installed MVC, but the references in the web.config – we copied from the Sitecore instance – probably do not match. By re-installing the MVC Nuget package the web.config gets updated with the proper assembly versions.

  1. Open the Nuget “Package Manager Console”
  2. Type: Update-Package -reinstall

Now remove all code from the RegisterRoute method in file App_Start/RouteConfig.cs, publish the project and check your Sitecore instance again, it should be working now.

Leave a Reply

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