Intellisense and JavaScript in Visual Studio 2012

In short use _references.js file with your web projects.  What is _references.js?

With the latest Visual Studio a new file _references.js is found in the scripts directory.  As you probably know, the `// <reference path=”…” />` syntax was introduced in Visual Studio long time ago to make you able to have intellisense in any JavaScript file to include everything defined in the JavaScript located at this path.  Said another way if you write the very first line in any JavaScript file, say “my-page.js”, and make sure the path points to the proper jQuery file, when you write code in “my-page.js”, you’ll get intellisense for everything in the jQuery file.


The quality of the intellisense will vary based on the referenced jQuery file, whether it’s minified file (least intellisense info, only member names, sometimes), just standard source/debug file, or even one that VsDoc comments (best intellisense, might even have notes on what types you need to pass to methods, when defined in VsDoc comments).


Visual Studio will give you intellisense from all files that have references in the “_references.js” file. This way you can define the global / common files you use all the time. This might include some library files like jQuery, or some files you use everywhere in the project like some internal utilities files.  In addition, for related files, you can use the “<reference >” syntax on top of every file to connect them (from intellisense point of view).


There is only one _references.js file for each project and is located in the /scripts directory.


You can manage this file manually or in the latest Visual Studio  release you can add/edit references via Tools > Options > Text Editor –> JavaScript –> Intellisense –> References node



comments powered by Disqus