Introduction
This article is the final product of hours and hours and hours of frustration due to the use of JQuery in a Web Application I was developing on my own in Visual Studio 2008. Visual Studio 2010 has a great JavaScript support but, until Visual Studio 2005 the attention for JavaScript was very poor. Visual Studio 2008 was yet a big step ahead, but the explosion of the JQuery library and the ease of deployment in almost any project has shown all the limitations of a platform that is starting to grow old. Although Visual Studio 2010 is a really good IDE, there are cases where you are tied to use version 2008, and this people is the target this article has been written for.
Searching for a solution to the infamous “Error updating JScript IntelliSense” problem will give you the bad sensation that at Microsoft they don't want to put too much of effort to guarantee the support for JQuery in Visual Studio 2008.
Moreover, the same JQuery website offers JQuery 1.4.1 as the last and most updated version of the library that is shipped with a documentation file associated. Most people on the forums will suggest you to both upgrade your IDE to Visual Studio 2010, or downgrade your JQuery to 1.4.1, which is also the last one that they guarantee to be tested and fully working in Visual Studio 2008. Well, know what? None of them can be accepted as a solution! There are changes and bug fixes from version 1.4.1 to version 1.6.1 that I want in my Web Application, and I’m going to show how you can circumnavigate this problem and leverage the full power of both JQuery 1.6.1 and the Visual Studio 2008 Intellisense.
Prerequisites
- Visual Studio 2008
- Visual Studio 2008 Service Pack 1
- JScript Editor support for “-vsdoc.js” IntelliSense documentation files
- JQuery 1.6.1 (last version at the time of writing) with documentation file
Reference Pages
Searching the Internet for “jquery-1.6.1-vsdoc.js” will bring you to the Microsoft Ajax Content Delivery Network page (http://www.asp.net/ajaxlibrary/cdn.ashx), which we will use as our reference page.
Here we can find everything we need. If you haven’t already done it, but I doubt, go and install as soon as possible the Visual Studio 2008 Service Pack 1. This will serve as a prerequisite for the hotfix KB958502 that we’ll install later.
Installing the Service Pack 1 may even take a couple of hours, so be patient ... when finished also install the hotfix. This patch adds JScript Editor support for “-vsdoc.js” IntelliSense documentation files. When you’ll include one .js file in your project, Visual Studio 2008 will automatically see if there’s in the same folder a file with the same name but ending with “–vsdoc.js”. This file contains comments to the code, that are appropriately formatted to be used as Intellisense tooltips. We’re now ready to set up our project.
Setting Up a Solution
Create one blank Web Application. In our reference page, scroll down until you find the section where third party files are hosted through the Content Delivery Network. At the top of this section, you’ll find just all the JQuery files that we need. Copy the first 3 paths and download all three files in your project folder.
After you’ve added your files to your project, you should be in this situation:
Now take the file jquery-1.6.1.js (yes, the full one, NOT the minified) and drop it in the head section of the Default.aspx page. If you have done correctly, you’ll have:
<head runat="server">
<title></title>
<script src="Scripts/jquery-1.6.1.js" type="text/javascript"></script>
</head>
And after a couple of seconds .. ta-da ! Just the error we wanted to have !
After all, you can think that the –vsdoc.js file is just a documentation file. If we haven’t found a solution on the web, we can try and make the solution ourselves, and as long as we respect the JavaScript syntax we can type in it whatever we want to help the parser to read that file. Just don’t touch the comments!
The error reports some problem at line 1504 of the –vsdoc.js file. So let’s open that file and go to line 1504. We don’t find anything broken there, but we do find something at the next line, where there’s an undefined assignment that looks like this:
1505: "triggered": };
So let’s fix it and place an empty object just to calm down the JavaScript parser:
1505 "triggered": {} };
Now save, and hit CTRL + SHIFT + J to update the Jscript Intellisense. Cool! The error went away but a warning similar to the first one pops up:
This time, the error is at lines 2648 and 2649, so let’s go straight there in our –vsdoc.js file and indeed find something quite unusual:
2549 "checkClone": ,
There’s another undefined assignment there. While a modern browser’s JavaScript engine can handle that and live with such assignments, a parser that is meant to provide you code assistance may not like it very much, so let’s fix this also to:
2549 "checkClone": true,
Save again, and hit CTRL + SHIFT + J to update the Jscript Intellisense, again. If today is your lucky day (and you've crossed your fingers correctly) you’ll see “Ready” in the Visual Studio status bar, and no more errors in the Errors pane. Now remove the reference to jquery1.6.1.js that we have put in our Default.aspx page, and replace it with a reference to the minified version of JQuery that is surely the one that we’d like to eventually deploy. Your page should look like this in the head
section, now:
<head runat="server">
<title></title>
<script src="Scripts/jquery-1.6.1.min.js" type="text/javascript"></script>
</head>
Now let’s add a new JavaScript file to our project, and at the very top of the file a commented reference to our –vsdoc.js documentation file, like this:
Let’s try to type $
in the JavaScript file and ...
Wow, the Intellisense is working … it looks promising! Try to type something more to see if the documentation has also been loaded:
Observe how Visual Studio 2008 is now able to offer a full Intellisense and method documentation support to JQuery 1.6.1!
Considerations
The only question to which I don’t have an answer is why Microsoft released a bugged documentation file for JQuery 1.6.1.