Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable the view hot-reloading in Rider? [duplicate]

I'm writing a MVC app using Rider, and a behavior bothers me: when I modify the view, I must rebuild the solution and relaunch it to see the changes. Is it possible to see the modified view directly when I reload the site from the browser?

By the way, the IDE (or dotnet?) doesn't consider a view change to be a rebuild-triggering change. I must click on "Rebuild selected project" by hand, and then I can launch the modified version of the app. Why is that?

like image 491
Boiethios Avatar asked Dec 10 '22 01:12

Boiethios


1 Answers

This is not an issue with Rider, it's fundamentally how ASP.NET MVC Core works. You need to enable Razor runtime compilation. From the docs (emphasis mine):

Razor files are compiled at both build and publish time using the Razor SDK. Runtime compilation may be optionally enabled by configuring your application.

Note that run time is not included in this list by default. To change this behaviour:

  1. Add the Nuget package Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation.

  2. Change your Startup.ConfigureServices code to include runtime compilation:

    services
        .AddControllersWithViews()
        .AddRazorRuntimeCompilation();
    
like image 51
DavidG Avatar answered Jan 06 '23 20:01

DavidG