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

1

6

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?

Bump answered 9/10, 2019 at 9:21 Comment(0)
H
17

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();
    
Haematopoiesis answered 9/10, 2019 at 9:24 Comment(3)
I've updated to dotnet core 3 and solved some warning, then I've added the method AddRazorRuntimeCompilation. It doesn't work, tho: I don't see the changes when I update the view.Bump
Ok, that worked with this answer: https://mcmap.net/q/116455/-net-core-mvc-page-not-refreshing-after-changesBump
For use with Rider and/or Razor Class Libraries (RCL), see this answer.Muckrake

© 2022 - 2024 — McMap. All rights reserved.