Get Visual Studio syntax highlighting for alternate file extensions

Question:
How do I configure things so that I can get proper code highlighting when I have a file that is a standard format (XML, or SQL) but has an alternate extension (.DNN, .SqlDataProvider)?


Answer:
Edit the registry (Warning: This is dangerous!  Backup the registry first!  I take no responsibility for any damage this may cause).  Also, you need to change 7.1 if you are not using Visual Studio 2003:


Under this subkey:  [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\7.1\Languages\File Extensions], add a new key for whatever file extension you want to add syntax highlighting for (ie, .DNN or .SqlDataProvider).  It should show up as a little folder icon.

For the default REG_SZ, change the value to equal the GUID for the file extension you want to copy (ie, for .SqlDataProvider use the same GUID as for .sql).  Copy any other DWords, values, etc. (just copy everything from the key of the extension you want to copy).

This entry was posted in Uncategorized. Bookmark the permalink. Follow any comments here with the RSS feed for this post.

6 Responses to Get Visual Studio syntax highlighting for alternate file extensions

  1. usr says:

    thanks a lot, used that registry trick to colorify my bison/flex scripts.

    the "open as" method somehow did not work, maybe because it already defaulted to plain text which is the same editor with the highlighting disabled or something like that.

  2. Graham Cottle says:

    Hi,

    I found this via Google and have managed to implement most of it. I can open a jsp page in VS2003 and it highlights syntax etc.

    It will also provide the closing tag when I open a new one. eg </td> after <td>.

    However, instead of being able to see the HTML designer, I get the XML designer, which refuses to load, since it doesn’t like the jsp.

    What else would I need to do to make the Studio open the file and give me the HTML Editor?

    Also, is it possible to get the intellisense for HTML (I know I won’t get the JAVA bits)?

    Below are the registry entries which I made.

    Windows Registry Editor Version 5.00

    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\7.1\Editors\{C76D83F8-A489-11D0-8195-00A0C91BBEE3}\Extensions]

    "jsp"=dword:00000028

    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\7.1\Editors\{8281C572-2171-45AA-A642-7D8BC1662F1C}\Extensions]

    "jsp"=dword:00000027

    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\7.1\Languages\File Extensions\.jsp]

    @="{58E975A0-F8FE-11D2-A6AE-00104BCC7269}"

    "unused"="HTML"

    As for why use jsp, it’s because I’m working on an SAP project which uses jsp. I’m a .NET developer, so anything I can use which gives me the niceties of VS is good.

    Thanks for the tip so far – it is very useful.

  3. Darrell says:

    Nice tip Gavin. Thanks!

  4. Gavin says:

    If you also want to get the other nice features (such as auto-formatting when editing .jsp pages in the HTML editor, for example) find the editor that you want under \7.1\Editors (which would be the ‘HTML Editor’ in this case) and add the extension in the \Extensions key as a DWORD. The value for the DWORD seems to change a bit, but if you just copy what’s already there it works fine.

  5. Darrell says:

    Joel – yes that is easier! Nice tip.

  6. Joel Ross says:

    There’s a better way to do this for a few of the file types, such as XML! When you are in the file -> open dialog box in VS.NET, click the arrow on the Open button, and choose open with…

    In the new dialog, select the type of editor you want to edit the file with, then click "Set as Default" and the next time you open a file in VS.NET with that same extension, it uses the default highlighting. I used this with .build files for NAnt, which is just XML.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>