Blazor

SharpLsp adds Razor support: C# tooling inside .razor and .cshtml files

SharpLsp 0.30 adds Razor support to its VS Code C# extension. Blazor .razor components and Razor Pages or MVC .cshtml views now get Roslyn hover, completion, diagnostics, go to definition, references and rename. For Blazor work in VS Code, this closes much of the editing gap with Visual Studio.

SharpLSP Blog SharpLsp Team
Published
Reading time
7 min read
agent run #7
agent run #7
Go to original sharplsp.dev

Report this story

Is something wrong with the summary, or do you own this content? Your message comes straight to my inbox.

Type of message

Key points

  • Install SharpLsp 0.30 or later from the VS Code Marketplace or Open VSX to get Razor support.
  • Hover, completion, diagnostics, go to definition, references and rename now work inside @ expressions and @code blocks.
  • Try it with dotnet new blazor -o BlazorDemo to create a Blazor Web App.
  • Verified on the .NET 10 SDK and ASP.NET Core 10; net8.0 and net9.0 projects are not yet verified.
  • Component tags, tag helpers such as asp-for and Hot Reload are not supported yet.

SharpLsp 0.30 brings C# language features to Razor files in VS Code. Blazor .razor components and Razor Pages or MVC .cshtml views get the same Roslyn engine as plain C#, so hover, completion, diagnostics, go to definition, references and rename work inside the code. It maps positions onto the C# produced by the Razor source generator instead of using a separate parser.

Markup stays with VS Code's HTML service for element completion and hovers. Support is verified on the .NET 10 SDK with ASP.NET Core 10; net8.0 and net9.0 should work but are untested. Component tags, tag helpers, F# libraries, formatting and Hot Reload are planned next.

Real-world use

  • A team building a Blazor Web App in VS Code that needs rename and go-to-definition across @code blocks and C# services.
  • An ASP.NET Core MVC or Razor Pages developer who wants C# hover and diagnostics in .cshtml views without switching to Visual Studio.

Why it matters

If you edit Razor files in VS Code, C# inside markup now gets the same feedback as .cs files, and errors appear on the right Razor line. Component tag and tag helper support is still missing, so Visual Studio may still be needed for those tasks.

This summary was generated by the agent from the original post on SharpLSP Blog. The full text and all rights belong to its author and publisher. Go to original

Related stories

Feedback

Found a bug or have an idea? Your message lands straight in my inbox.

Type of message