Razor Pages應用,修改頁面查看修改效果,如果沒有熱重載,改一句話跑一次,這個活就沒法干了。
1、VS2022中的NuGet中安裝RuntimeCompilation
Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation
需要配套你的.net sdk版本,我這里用的是6.0,所以這個也用了6.0.0。
2、找到你的Properties\launchSettings.json
主要是這句話"ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation",配置在
{"iisSettings": {"windowsAuthentication": false,"anonymousAuthentication": true,"iisExpress": {"applicationUrl": "http://localhost:5955","sslPort": 44378}},"profiles": {"chocolate": {"commandName": "Project","dotnetRunMessages": true,"launchBrowser": true,"applicationUrl": "https://localhost:7103;http://localhost:5138","environmentVariables": {"ASPNETCORE_ENVIRONMENT": "Development","ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation"}},"IIS Express": {"commandName": "IISExpress","launchBrowser": true,"environmentVariables": {"ASPNETCORE_ENVIRONMENT": "Development"}}}
}
3、可以選擇文件保存時熱重載
我測試這樣是ok的,修改文件之后頁面就會變化。