Asp.net-Core
是否可以使用 .NET Core 更改 .cshtml 視圖並立即查看更改?
語境
在我的 .NET Framework 4.x ASP.NET MVC 項目中,使用 Visual Studio IDE 時,可以編輯
.cshtml視圖、保存,然後在瀏覽器中按ctrl+F5並立即查看更改。這似乎不再適用於 ASP.NET Core 應用程序(使用 Visual Studio 2019 和 .NET Core 3 Preview 5)。
問題
ASP.NET Core 中是否缺少此功能?這是預覽問題嗎?還是我錯過了什麼?
從 ASP.NET Core 3 開始,預設情況下不再啟用此功能,但可以按照此處所述重新啟用:
Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation使用包啟用執行時編譯。要啟用執行時編譯,應用程序必須:
- 安裝Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation NuGet 包。
- 更新項目的
Startup.ConfigureServices方法以包括呼叫AddRazorRuntimeCompilation:services .AddControllersWithViews() .AddRazorRuntimeCompilation();