How to create custom CSS intellisense schema in Visual Studio 2005 and 2008


Some time ago I described how to add custom HTML markup intellisense and validation schema to VS 2005 and Visual Web Developer Express. Same steps apply to VS 2008. Here I am going to describe how to add custom CSS intellisense schema.


First of all, you can simply modify existing schema. For example, technically CSS 2.x only defines 16 color names while all modern browsers recognize many more. You can borrow color definitions from IE6 CSS schema and include then in CSS 2.1 schema. See my previous blog post for details. If you want to define completely different CSS schema, here are step by step instructions:


1. Copy existing schema file to use it as a template. CSS schemas are in Program files\Microsoft Visual Studio 9.0\Common7\Packages\1033\schemas\CSS (1033 is for English version, substiture number is you are using localized build). For example, copy CSS21.xml to MyCSS.xml.


2. Open MyCSS.xml and edit it to create desired schema. Note that schema folder contains CSS.XSD file which is XML schema for the CSS schema file.


3.  Open RegEdit go to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\9.0\Packages\{A764E895-518D-11d2-9A89-00C04F79EFC3}\Schemas. Typically there are 4 entries there, named Schema 1, Schema 2, etc. 


4. Create a new entry that immediately follow the last one. Do not leave any holes in the numbering sequence. For example, if you see Schema 4 as last entry, create Schema 5.


5. Under the new key create File REG_SZ value and specify MyCSS.xml


6. Create Friendly Name REG_SZ value and specify name for the schema. This name will appear in the schema dropdowns in the CSS editor toolbar.


You are done. Restart IDE, open CSS file and your new schema should appear in the dropdown. If schema does not load, most probably is does not validate against css.xsd.


Comments (6)

  1. Great post Mikhail.

    I’ve been wracking my brain on how I could create an intellisense file for JS. I have a library that I use for development and it would sure be a real benefit if I could define it in intellisense.

    Any thoughts or pointers? reference docs?  

    I really appreciate the help.

  2. mikeark02@hotmail.com says:

    You can’t customize script intellisense in VS 2005, but VS 2008 will pick up your script files automatically and generate all necessary intellisense information. VS 2008 script intellisense engine is 100% brand new. ave a look here: http://blogs.msdn.com/webdevtools/archive/2007/03/02/jscript-intellisense-in-orcas.aspx

  3. Eric says:

    Hi Mikhail,

    I was wondering if I can create custom schemas for text files like LDIF. Those files are text files with some simple rules like:

    – every line begining with # is a comment;

    – every line starts with a keyword followed by colon followed by text;

    – keywords are restricted to values from a list;

    – for some keyords, the following text should be one of a pre defined list ;

    Do you know if this kind of thing is possible?

    Best regards,

  4. Martin Volerich says:

    Can this same process (customizing the css intellisense & validation) be done for Expression Web / SPD?

  5. mikeark02@hotmail.com says:

    I believe so. Expression uses similar intellisense engine derived from VS 2005 code base.

  6. mikeark02@hotmail.com says:

    Well, in VS is not trivial to add intellisense to a new file type unless it is some sort of a common format already recognized by VS (such as XML). In LDIF case you would have to implement ‘language service’ in C# or C++ that provides coloring and statement completion.