Sean Holmesby

.NET and Sitecore Developer


Fixing Visual Studio IntelliSense in Sitecore MVC Views

IntelliSense in Visual Studio is a fantastic auto-complete feature that greatly improves your Sitecore development, however I’ve occasionally seen this not working in my MVC solutions.

01 - HTML Sitecore Helper not working

In particular, I was seeing the following error highlighted around any calls to the @Html.Sitecore() helper:-

‘System.Web.Mvc.HtmlHelper<Model>’ does not contain a definition for ‘Sitecore’ and no extension method ‘Sitecore’ accepting first argument of type ‘System.Web.Mvc.HtmlHelper<Model> could be found.’

This would mean that I could not get auto-complete on the @Html.Sitecore() helper, nor would I get auto-complete for my properties on my Glass Models.

While this error had be seen in Visual Studio 2013, I was using the latest update of Visual Studio 2012 (Update-4), and shouldn’t have had this issue.

In order to get IntelliSense working in the Views:-

  1. Include the Sitecore Web.Config file in your project.
  2. Include the Sitecore /Views/Web.Config file in your Views folder. (it should have a reference to the Sitecore.Mvc namespace).
  3. Include some necessary App_Config files in your project’s directory. (You can still have these excluded from your project, or you can follow the ‘Build Action: None’ steps below)
    • You will need the App_Config/Prefetch folder, and the configs in the root of App_Config (not the Include or Security folders).
  4. Ensure Sitecore.Kernel.DLL and Sitecore.Mvc.DLL are referenced in your project, and are set to CopyLocal=true.
    • we need these DLLs to end up in the bin directory of the project.

Now, typically we’re told to have CopyLocal set to false for Sitecore DLL references, as it can slow down the build…but here we need it to enable IntelliSense.

What we can do is have the project use CopyLocal=true, then exclude the DLLs in the TDS project settings. TDS even has a default setting for this, where Sitecore.*.DLL is excluded.

02 - TDS Exclude DLL

This means that the DLLs are copied to the project’s bin directory, but they’re not copied across to my website’s bin directory. (Remember, you should be working outside of the webroot).

With the configs added to the project, I can also make TDS ignore the configs by ensuring that each config file’s Build Action property is set to None. This tells TDS not to copy that file during the build process. (if you don’t need the file, you could just not include it in the project…just have it sitting on the file system in the project’s directory).

Now, my project has everything it needs for IntelliSense, and I’m not pushing files to my website that I shouldn’t be. (they’re already there anyway).

03 - Sitecore Helper IntelliSense 04 - Glass Property IntelliSense

9 Responses to Fixing Visual Studio IntelliSense in Sitecore MVC Views

  1. Gorhal says:

    Great post 🙂

  2. Alen says:

    Just a note that setting CopyToLocal=True is a bad idea if you work in Website folder because cleanup or rebuild action will remove all the assemblies from bin folder.

  3. sholmesby says:

    Yep, good point Alen.
    And then, if you work inside your website folder you won’t need to do a lot of the things mentioned here (like the App_Config files) as the project will already see them in place.

  4. Dan says:

    Thanks so much for this — I spent a day and a half fighting with this problem before I found this post!

  5. Ivan says:

    In my solution setting CopyToLocal only for Sitecore.Mvc did the trick.
    Great instructions. Thanks for posting them out!

  6. alin says:

    This is a cool solution however, if you have a multi project solution like I do 🙂 and you have a TDS project per normal project then you need to do a lot of manual configuration in each TDS project. I am no TDS expert but would be really cool if there could be some general settings for all the TDS projects in a solution.

    • sholmesby says:

      Thanks Alin.
      With TDS versions 5+ there is a way to do this once for all TDS projects in your solution.
      Right click on the solution, and select Add TdsGlobal.config file.
      You can then set your settings in that file and they will be used by all of your TDS projects.

      Better yet, if you don’t want to commit your own settings to source control, you can duplicate that TdsGlobal.config file under the name TdsGlobal.config.user, in the same file system location, and place your settings in there.
      That way each developer can have their own settings, and only have to configure them once for the entire solution.

      Let me know if this helps.

  7. Arunkumar Ponnusankaran says:

    Nice post Sean!!! Most of my searches in google are landing up on your site or posts. Hereafter for all my queries, I am gonna ping you directly 🙂

Leave a Reply

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