首页 > 解决方案 > Asp net core 3.1 webapp doesn't refresh on modify razor template

问题描述

i'm using visual studio code on mac osx for running a simply web app in asp net core 3.1. I run application with command dotnet run in visual studio code terminal. Now, if i modify a .cshtml template and refresh my browser, modify don't show.

Why? How can i resolve?

Thanks

标签: macosasp.net-corerazorvisual-studio-code

解决方案


To enable runtime compilation in vs code, you need to follow below steps:

1.Add a reference to the Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation package,run the command in the terminal

dotnet add package Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation -v 3.1.0

2.Update the project's Startup.ConfigureServices method to include a call to AddRazorRuntimeCompilation.

services.AddControllersWithViews().AddRazorRuntimeCompilation();//for MVC

//services.AddRazorPages().AddRazorRuntimeCompilation();//for Razor Pages

Refer to https://docs.microsoft.com/en-us/aspnet/core/mvc/views/view-compilation?view=aspnetcore-3.1#runtime-compilation


推荐阅读