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).
5 thoughts on “TIHIDI: Setup a Visual Studio 2015 Sitecore 8.x MVC Solution”
Thanks Akshay! I had set up a solution quite similar way for my Sitecore 8.1 Sandbox…your post proved me right!!! 🙂
Exactly what I was looking for…!! Thank you!!!
Great stuff Akshay.
A couple of things to note to other readers:-
– Step 5 you have ‘Add Application Insights’ unchecked on the right side. This is important, because I believe the default is that it’s checked, and it brings in a lot of things that you don’t need in a project. So make sure you have it unchecked!
– The addition of the Web.config, Sitecore.config, DLL references etc. plus the additional line in the Views/Web.config, are largely due to adding Visual Studio IntelliSense to your project. This can be seen here:- http://www.seanholmesby.com/fixing-visual-studio-intellisense-in-sitecore-mvc-views/
In the case where you get more advanced, and say, add Glass Mapper to your project, to include Glass IntelliSense you’ll need to ensure you do similar steps with the Glass DLLs (CopyLocal=true) and namespaces.
First, thank you for taking time to go through the blog post. Totally agree. The Application Insights and the Azure could are two checkboxes I uncheck the first time and Visual Studio remembers it for the subsequent projects.
I always come across dll reference issues like “Could not load file or assembly ‘Microsoft.Owin, Version=126.96.36.199” or series of other issues. what I am doing wrong here.
You could install it from Nuget -> Install-Package Microsoft.Owin