Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio see html changes without rebuilding code

Working with Microsoft Visual Studio Community 2019.

I have a project ASP.NET core (but I dont think it is related to core)

When I run the project via IIS Express\project button

enter image description here

When I modify a file (cshtml) "html file" in Core project and click F5/Ctrl+F5 I dont see the changes applied. I need to stop the project and run the project again to see html changes. I understand when modifying the source code I need to rebuild and rerun.

Is there a configuration in VS I need to set so that html changes get reflected when I refresh the page, would save me some much time to see the changes without rebuilding/rerunning?

like image 932
Benk Avatar asked Oct 18 '25 15:10

Benk


1 Answers

You can install NuGet Package

Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation

first, and in ConfigureServices(), add:

services.AddMvc().AddRazorRuntimeCompilation();

then you can just refresh the cshtml to see the changes.

2024 update

In .Net 8+ Core, there is no ConfigureServices() and instead looks like this:

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllersWithViews().AddRazorRuntimeCompilation();
like image 118
Jerry Cai Avatar answered Oct 21 '25 08:10

Jerry Cai