This blog post will show you how I setup a Visual Studio 2015 MVC solution for Sitecore 8.1. I work outside of the web root, some work right in the web root. It truly depends on the tools you use, team size, location and your preferences.
TIHIDI: Stands for This Is How I Do It. I am going to write a series of blog posts going through how I do Sitecore related work. Hope it helps you!
1. Setup a site on your local. Refer to:
- Install Sitecore 8.x
- Install MongoDB 3.2.7 for Sitecore 8.x in one step!
- Install Sitecore Instance Manager (SIM)
2. Setup the folder where your solution is going to live. I setup the folder structure similar to what is shown below:
You ultimately want to have several folders under Dependencies based on the different applications/modules or third party integrations you might have.
3. Copy the Sitecore.Kernel.dll and Sitecore.Mvc.dll from the website\bin folder in to the Dependencies\Sitecore folder.
4. Open Visual Studio 2015. I set the options on Visual Studio 2015 to always Run as Administrator, this helps especially when you are debugging your code by attaching to the w3p process.
5. Create new Visual Studio 2015 Project:
- Click on File > New > Project.
- Select Web > ASP.NET Web Application.
- Specify Name.
- Select location.
- Select other options as necessary.
- Click OK button
6. Once that is done you are presented with another dialog. Select Empty option in the Template section and select MVC in the Add folders and core references for section. Click the OK button to continue.
This will create the base solution as shown below:
7. Delete the Web.config and Global.asax.
8. Copy the Web.config and Global.asax from the Website folder in to the TIHIDI.Web (Web project root) folder.
9. Create an App_Config folder in your Web project root.
10. Copy the ConnectionStrings.config and Sitecore.config from the Website > App_Config folder in to the TIHIDI.Web (Web project root) > App_Config folder.
11. Back in Visual Studio 2015, include the newly created App_Config folder.
12. Also include the copied Global.asax and Web.config.
13. Add references to the Sitecore.Kernel.dll and Sitecore.Mvc.dll in the Dependencies\Sitecore folder.
14. Open Views\web.config and add the following to the end of the <namespaces> node so that you can use @Html.Sitecore() in your views.
<add namespace=”Sitecore.Mvc” />
15. Restart Visual Studio 2015 and reopen the solution.
16. Rebuild solution.
17. At this point we have everything we need to deploy. Double check to make sure your MVC versions matchup before you deploy to the website. In my case, no additional work needed.
18. Setup a One Click Publish profile pointing to the website root. You can use post build scripts, TDS and other ways as well.
19. Finally publish.
20. Now that we have our solution publishing to the website, lets reload the site and the Sitecore admin.
All working as expected!
If you have any questions or concerns, please get in touch with me. (@akshaysura13 on twitter or on Slack).