A while ago I blogged about creating an extension in visual studio 2010 that ran JSLint on files. I started by getting a JavaScript interpreter based on the V8 engine to run JSLint and then just before publishing I discovered someone else had already started an extension. Luckily, that person proved friendly and over the last month I've been collaborating with him on the extension.

You can view the codeplex project here and also access it via the visual studio marketplace.

I am pleased with how it's come on - It has most of the features I can think of - run on build, exclusion of files and segments, making unused variables an error and exporting/importing settings. If you use Visual Studio 2010 and do JavaScript development, I hope you find this useful.

My experience of using the Visual Studio 2010 extension framework however was far from easy. Visual Studio is a complicated program admittedly, but everything I wanted to do seemed difficult - If a user right clicks on selection in the editor then get that selection - get the current file being edited - add errors on to the error list - All these things seem either more difficult than they should be or only achievable in quite ugly ways. For instance, here is the code that when a user right clicks on an editor retrieves the filename in order to check whether it is a JavaScript file..

IVsMultiItemSelect mis;
IVsMonitorSelection monitorSelection = (IVsMonitorSelection)Package.GetGlobalService(typeof(SVsShellMonitorSelection));

monitorSelection.GetCurrentSelection(out hierarchyPtr, out projectItemId, out mis, out selectionContainerPtr);

IVsHierarchy hierarchy = Marshal.GetTypedObjectForIUnknown(hierarchyPtr, typeof(IVsHierarchy)) as IVsHierarchy;

if (hierarchy != null)
{
	object value;

	hierarchy.GetProperty(projectItemId, (int)__VSHPROPID.VSHPROPID_Name, out value);

	if (value != null && value.ToString().EndsWith(".js"))

If you are in the unfortunate position of writing a visual studio extension, here are some of the blog posts that helped me. Without them, I would have been truly stuck.

David DeWinter - Dynamic Menu Commands in Visual Studio Packages - Part 3 - Explains how to dynamically turn on and off menu commands. We needed this because the XML used to attach commands was sometimes not specific enough - for instance all web site files are web item nodes, where as a JavaScript file embedded in a project is a JavaScript item node..

DiveDeeper's blog » LVN! Sidebar #1 - Automatically loading packages - How to make your extension load on startup instead of when a user accesses a menu that you've stuck a command on (required if you need to show/hide menu items dynamically)

Visual Studio Extensions Forum - How to add parsing errors to ErrorList window? - It took a while to realise that to add errors to the error list, you needed an error list provider with a link to a registered and running service (where as the task list just requires a function call).

Using EnableVSIPLogging to identify menus and commands with VS 2005 + SP1 - A lot of difficulty comes from having an XML file specify where your menu items should go and that it uses constants that don't seem to be defined anywhere in order to add menu's to places. This registry hack makes visual studio show you the guid that relates to particular context menus in order to help you write the XML file and get your new menu item to appear in the correct place.

This is the C file that defines the guids available in the XML file.

Many thanks to Adrian Conlin for the awesome icon.