asp.net core 3.0 在Debug时不重启,自动重新编译View

.net core3.0之后,在debug的时候,如果修改View(cshtml),默认无法立即刷新页面就生效,需要停止,重新启动项目才可以. 这样毫无疑问是非常麻烦.

 

解决方法

首先安装Nuget包:

Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation

  

然后在Startup里的ConfigureServices中加入如下片段:

public void ConfigureServices(IServiceCollection services)
{
    services.AddDbContext<ApplicationDbContext>(options =>
    {
        options.UseSqlite("Data source=calendar.db");
    });
 
    services.AddControllersWithViews()
            .AddRazorRuntimeCompilation();
 
}

至此,大功告成!

posted on 2019-12-17 16:49  Gary_Zhu  阅读(1022)  评论(0编辑  收藏  举报