Posted on:
Categories: SharePoint
Description:

​Let me start this post with a statement: I'm a developer and developers love IntelliSense. If you are a developer too, you know what I'm talking about!

Recently, I created a SharePoint-hosted add-in in Visual Studio 2013. While starting to code, I recognized that IntelliSense wasn't working correctly. Here is an example:

I tried to create a new ClientContext, but as you can see, IntelliSense is not providing the proper functions nor properties:

 

In fact, all the JSOM functions and properties were missing, which makes coding a SharePoint-hosted add-in needlessly difficult.

IntelliSense is a very helpful feature, and I refused to continue coding without proper IntelliSense. So I started some investigation to see why IntelliSense wasn't able to show the JSOM stuff.

First, I checked the _references file which is usually located in the project's Scripts folder. This file was existing, and its content looked correct.

 

In a nutshell, this file is referencing the SharePoint JSOM libraries and the files listed here are supposed to be added to the IntelliSense database – but for some reason, this isn't working for my current project.

My next step was to check if the _references file is actually used by Visual Studio to feed the IntelliSense database. To check this, I opened <Tools> <Options> in Visual Studio. In the text box at the top, I typed in 'JavaScript' and the following dialog is shown:

 

I clicked on References just below IntelliSense to see which libraries were included to build the IntelliSense database. The file _references.js was included just like some other libraries. Although _references file was listed here, it was not used to update the IntelliSense database.

The basic configuration looked ok, and so I was looking for a workaround to get IntelliSense to show the functions and properties of the JSOM objects.

I manually downloaded the file SP.runtime.js from SharePoint and added it to the Scripts section of my Visual Studio project.

 

Because I did not want this file to be re-deployed back to SharePoint each time the app gets deployed to SharePoint, I changed the Deployment Type of this file to NoDeployment and I repeated this with the file SP.js.

Time for a new test - and this time IntelliSense was working as expected!

 

Now the IntelliSense database has been updated properly and was able to show all functions and properties which are part of the JSOM libraries – and this makes coding with JSOM a lot easier!

It looked like Visual Studio wasn't able to access the referenced files which are listed in _references.js. Adding them as downloaded copies to the Scripts folder in my Visual Studio project enables IntelliSense to access them and update its internal database. As long as those files are kept locally and are not deployed back to SharePoint, this workaround can be used to fix the initial IntelliSense problem. But keep in mind: as those files are local copies now, they won't get updated automatically!