25

Can I tell Visual Studio how treat a file with a custom file extension? I want to be able to open a file with ".xxx" extension in Visual Studio and have CSS highlighting.

I've tried to do it by going to VS -> Tools -> Options -> Text Editor -> File Extension but in the Editor drop down there is nothing to specify "treat it as CSS".

dev.e.loper
  • 35,446
  • 76
  • 161
  • 247
  • possible duplicate of [Open a file in Visual Studio's CSS Source Editor](http://stackoverflow.com/questions/2346243/open-a-file-in-visual-studios-css-source-editor) – bdukes Aug 30 '10 at 15:27

3 Answers3

59

In Visual Studio go to Tools > Options > Text Editor > File Extension

There you can add specific extensions and choose which 'Editor' Visual Studio uses for that extension.

jedi.jesse
  • 773
  • 5
  • 11
  • 6
    I know this answer came super late, but I think anyone searching for this will end up here, and it's now far simpler than it apparently used to be. – jedi.jesse Feb 12 '16 at 20:00
  • 1
    There is no CSS option in `Tools > Options > Text Editor > File Extension` Editor dropdown. – Ben Feb 03 '20 at 21:19
  • In Visual Studio 2017, there is a CSS Editor in the list. – KWallace Mar 14 '20 at 19:53
  • When using this method, VS pops-up a dialog with an input box for extension name and a drop-down for language (ex: C#, JavaScript). It doesn't matter if you use a period/dot before the extension because VS understands it both ways. – Gen1-1 Dec 02 '22 at 15:52
6

There is a registry hack that you can use. http://www.engagesoftware.com/Blog/EntryId/117/Editing-SqlDataProvider-scripts-within-Visual-Studio.aspx

Basically, you look at HKLM:\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\9.0\Languages\File Extensions\.css (changing the version number based on your version of VS, and removing Wow6432Node if you aren't on a 64-bit OS) and make a copy of that, calling it .my-custom-extension

UPDATE According to a similar Stack Overflow question, for some extensions (i.e. CSS), there's another step to be taken. It says to take the GUID from the extension that you're copying, and find its entry in HKLM:\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\9.0\Editors and add a DWORD value in its Extensions key like the existing css value. That question also points to an extension in the VS gallery that does that. However, even after doing that, I'm still unable to get syntax highlighting, myself...

Community
  • 1
  • 1
bdukes
  • 152,002
  • 23
  • 148
  • 175
  • I went to the path in regedit, made a copy of '.css' key and renamed it to '.less'. Restarted my PC, opened '.less' file in VS but still no CSS highlighting. What else could I be missing? – dev.e.loper Aug 16 '10 at 14:17
  • I dunno. I'm seeing the same thing (that it works fine for `.SQL` but not for `.CSS`...) – bdukes Aug 16 '10 at 16:45
  • 1
    BTW, just closing Visual Studio is enough for changes to take effect, don't need to restart your machine. – bdukes Aug 16 '10 at 16:56
  • there is also an VS extension that does this for you. http://blogs.msdn.com/b/noahric/archive/2010/03/01/new-extension-css-is-less.aspx – dev.e.loper Aug 28 '10 at 22:56
2

Tested on Visual Studio 2019. Tools > Options > Text Editor > File Extension add your file extension with '.' like .ejs (Node.JS View Engine) and then set it to one of known editors and press add: .ejs >> HTML Editor Close and reopen the files with .ejs in VS & you will see HTML markups on them.