ASP.NET MVC 5 Razor (.NET Framework)
Visual Studio-style highlighting for ASP.NET MVC 5 / System.Web.Razor
The problemThe C# extension's Razor support only understands ASP.NET Core Razor. Open a view from an MVC 5 /
.NET Framework 4.x project and it compiles the view against the wrong page model, so every line goes red
( The usual workaround, mapping What this extension doesIt adds a dedicated ASP.NET MVC 5 Razor language (
What it does not doNo hover, go-to-definition, IntelliSense or real diagnostics inside views. Those need a compiler that
understands Identifier colouring is a heuristic, not binding. TextMate scopes InstallFrom a release: download From source:
How
|
| Setting | Default | Description |
|---|---|---|
aspnetMvc5Razor.takeOverCshtml |
true |
Switch .cshtml files to this language when they open. |
aspnetMvc5Razor.boldMarkupText |
true |
Show HTML text in bold, as Visual Studio does. |
aspnetMvc5Razor.visualStudioColors |
true |
Keep the Visual Studio palette in your user token colours (views only). Off removes it. |
aspnetMvc5Razor.namespaceRoots |
[] |
Extra namespace roots the workspace scan cannot find. |
Colours
The background colours are theme colours, overridable in workbench.colorCustomizations. Dark defaults were
sampled from Visual Studio 2026.
| Colour | Dark | Light |
|---|---|---|
aspnetMvc5Razor.codeBackground |
#464646 |
#F4F4F4 |
aspnetMvc5Razor.transitionBackground |
#D0D294 |
#FFFF96 |
aspnetMvc5Razor.transitionForeground |
#000000 |
#000000 |
aspnetMvc5Razor.staticType |
#4EC9B0 |
#2B91AF |
aspnetMvc5Razor.plainIdentifier |
#DCDCDC |
#000000 |
Token colours (keywords, strings, types...) are written for you. On start the extension generates Visual
Studio 2026 Dark rules from the installed Razor, C# and HTML grammars, one per concrete scope and every one
scoped to text.aspnetmvc5razor, and keeps them in your user editor.tokenColorCustomizations. Nothing
outside .cshtml views changes, and other rules you have there are left alone.
Why one rule per scope: themes rank a rule by how specifically it matches the token's own scope before
looking at parents, so a short text.aspnetmvc5razor storage loses to a theme's storage.type.var.
Matching the full scope name ties on specificity, and the text.aspnetmvc5razor parent then wins.
Commands: ASP.NET MVC 5 Razor: Apply Visual Studio Colours and Remove Visual Studio Colours.
How it works
.cshtml ──► TextMate grammar (syntaxes/) ──► token colours (your theme)
└─► Razor scanner (src/scanner.js) ──► decorations: code background, transitions, bold text
src/semantics.js classifies member-chain roots (see above), src/roots.js learns namespace roots, and
src/palette.js builds the token colour rules.
src/scanner.js is a best-effort parser of MVC 5's rules for where C# starts and ends: implicit and explicit
expressions, code blocks, if/else/foreach/using/try and friends, @functions, @helper,
@section, @: and markup nested inside C#. It is not the Razor compiler: on malformed input it never throws,
it just stops colouring. A large view scans in about 2 ms, and decorations refresh 120 ms after you stop typing.
Development
| Command | |
|---|---|
npm test |
Scanner unit tests (node:test, no dependencies) |
npm run check-views -- <folder> |
Scan every .cshtml in a codebase and list likely misparses |
npm run build-grammar |
Regenerate syntaxes/ from the installed C# extension's Razor grammar |
npm run package |
Build dist/vscode-aspnet-mvc5-razor.vsix |
npm run install-local |
Package and install into VS Code |
When a view highlights wrongly, reproduce the construct in test/scanner.test.js first, then fix the scanner,
then run check-views against a real codebase to make sure nothing else moved.
Shipping a new version: see RELEASING.md for the checklist (version bump, changelog, tests, Marketplace upload, tag and GitHub release).
Credits
The grammar is generated from the Razor grammar in the C# extension (dotnet/vscode-csharp), which comes from dotnet/razor. Both are MIT-licensed.
