I am managing my style declarations in a .cshtml file so I can dynamically code values, for example color-codes that I need to be repeat often. I’m using MVC’s routing capabilities to serve up the stylesheet with a .css extension, so this is all opaque to the end-user.
The .cshtml file contains mostly CSS, of course, with only a few dozen values passed in dynamically, and some calls to helpers I’ve written to make the CSS easier to maintain, so I’d like to be able to view this file with CSS code-highlighting.
QUESTION:
Is is possible to set the language for syntax hightlighting manually for a given file with Visual Studio?
Note: I know this is easy with Notepad++, but I’d prefer to do everything with the same editor.
UPDATE: I’v realized this problem can (I think) be cooked down to “Where is the executable for the the CSS Source Editor (default) ?”. This is an option when choosing “Open With…” on a CSS file, but not an option when choosing “Open With…” on a .cshtml file, so if I could just navigate to its location using the “Add” button in that wizard, my problem is solved. But…where is that editor??!
UPDATE (2): My hack works, but as it is ugly, I’d still like to know how to open in the default CSS editor.
UPDATE (3): I could really use a solution here, and it seems a general solution would be beneficial in many circumstances. Hence the bounty.
UPDATE (4): OK, My hack really does work — you just have to open the file with the VS’s HTML Editor instead of the Razor editor.
Here’s my hack:
You can open a .cshtml file with Visual Studio’s HTML editor, and that editor will recognize CSS if nested inside
<style>tags. But since the<style>(or any) tag is invalid inside a .css file, and will cause styles to break, the way around this is to embed the open and closing tags in razor or CSS comments:OR:
Yuck. But it works.
update It does work — just be careful to select VS’s HTML editor and not the Razor editor when using “open with…”