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:
- Install a new Sitecore instance
- Create a new Solution/Project in Visual Studio
- Select ASP.NET Web Application as your project type
- Select the “Empty” template
- Check the “MVC” checkbox under the section “Add folders and core references for”
- Click OK
In the next few steps we copy some necessary files to your projects:
- On the same level as your solution file (.sln) create a new folder external.
- Select the files: Sitecore.Kernel.dll and Sitecore.Mvc.dll from the Sitecore instance to your new folder.
- 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.
- Open the Nuget “Package Manager Console”
- 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.