TIHIDI: Setup a Visual Studio 2015 Sitecore 8.x MVC Solution

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:

  1. Install Sitecore 8.x
  2. Install MongoDB 3.2.7 for Sitecore 8.x in one step!
  3. 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:

solution1

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.

solution2

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:

  1. Click on File > New > Project.
  2. Select Web > ASP.NET Web Application.
  3. Specify Name.
  4. Select location.
  5. Select other options as necessary.
  6. Click OK button

solution3

solution4

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.

solution6

This will create the base solution as shown below:

solution7

7. Delete the Web.config and Global.asax.

solution8

8. Copy the Web.config and Global.asax from the Website folder in to the TIHIDI.Web (Web project root) folder.

solution9

9. Create an App_Config folder in your Web project root.

solution10

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.

solution11

11. Back in Visual Studio 2015, include the newly created App_Config folder.

solution13

12. Also include the copied Global.asax and Web.config.

solution14

13. Add references to the Sitecore.Kernel.dll and Sitecore.Mvc.dll in the Dependencies\Sitecore folder.

solution12

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” />
</namespaces>

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.

solution15

solution16

19. Finally publish.

solution17

20. Now that we have our solution publishing to the website, lets reload the site and the Sitecore admin.

solution18 solution19

All working as expected!

If you have any questions or concerns, please get in touch with me. (@akshaysura13 on twitter or on Slack).

5 comments

  • Hetal Dave 1 year ago

    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!!!

  • Sean Holmesby 1 year ago

    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.

    Thanks,
    Sean

  • akshaysuraadmin 1 year ago

    Sean,
    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.

    Thanks.

  • Ashish 7 months ago

    I always come across dll reference issues like “Could not load file or assembly ‘Microsoft.Owin, Version=2.1.0.0” or series of other issues. what I am doing wrong here.

  • akshaysuraadmin 7 months ago

    You could install it from Nuget -> Install-Package Microsoft.Owin

Add your comment

Your email address will not be published.