在建立時勾選 啟用 Razor 執行階段編譯
Enable Razor runtime compliation
Properties/launchSettings.json 則有一個 ASPNETCORE_HOSTINGSTARTUPASSEMBLIES 變數啟用 cshtml 執行期編譯:
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation"
}
}
如果是已經建立但沒勾選的專案
手動安裝 Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation NuGet Package
比照上述加參數即可