.NET Core: Razor Runtime Compilation

By James Kenny
1 min read

Table of Contents

In .NET Core 3.1 by default if I made a change to the Razor view and hit save. The reload on the page wouldn't help. It would need me to close the the debugger and then relaunch it.

The reason for this was the AddRazorRuntimeCompilation isn't there by default now.


.NET Core uses the Razor Runtime compilation to compile the changes we make and allow us to see the updates when we are debugging. To add it back in is pretty straightforward.

First off we need the Nuget Package:

PM > Install-Package Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation

Once we have the package installed, we head to the startups.cs and add it into our configure services call

public void ConfigureServices(IServiceCollection services)
	// Your code here

That's it, once you make a change in your Razor view and hit save. It will be built at runtime and you can see the changes in the browser on a refresh.

Tagged in:

.net core

Last Update: February 17, 2020

About the Author