3

I was unhappy after moving to .NET 6 when I discovered that changes I made to the razor weren't being automatically compiled after clicking save. I spent months having to restart the whole web server every time I made a small change to the site I'm developing. I scoured the internet looking for a solution and even communicated with a Microsoft team member, all to no avail.

Luckily, my coworker stumbled into a solution that works perfectly and I wanted to share it with other people who are having the same issue.

mattersonline
  • 183
  • 1
  • 10

1 Answers1

2

Just add this library to the project file and it'll start working.

<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="6.0.1" />
mattersonline
  • 183
  • 1
  • 10
  • but do not forget to add also in the startup.cs the line _services.AddRazorRuntimeCompilation();_ more docs here https://learn.microsoft.com/en-us/aspnet/core/mvc/views/view-compilation?msclkid=ea37bcd0b51b11ecbb7d0f7cef12d7ef&view=aspnetcore-6.0&tabs=visual-studio – Steve Apr 05 '22 at 20:06
  • 1
    in my project ,it's builder.Services.AddRazorPages().AddRazorRuntimeCompilation(); – york May 10 '22 at 08:03