我正在最新版本 2.2 上构建 .NET Core MVC.我在更改 CSHTML 文件并刷新页面时遇到问题,我的更改未反映在浏览器中.我必须重新启动项目才能看到我的更改.这种情况已经发生了一段时间,所以我不确定是什么变化导致了这个问题.
I'm building a .NET Core MVC on the latest version 2.2. I have a problem when I make changes to the CSHTML file and refresh the page, my changes are not reflected in the browser. I have to restart the project in order to see my changes. This has been happening for a while now so I'm not exactly sure what change caused this issue.
我尝试过使用 chrome 的清空缓存和硬重新加载"以及其他浏览器都无济于事.这发生在使用 Visual Studio for Mac 和 VS Code 的 Windows 和 Mac 上
I've tried using the chrome's "Empty Cache and Hard Reload" as well as other browsers to no avail. This happens on Windows and Mac using both Visual Studio for Mac and VS Code
在默认的 .Net Core 项目中它运行良好,所以它一定是我项目中的某些东西在此过程中发生了变化.我想知道我需要从哪里开始才能调试这个问题?我尝试将 Startup.cs 和 Program.cs 中的几乎所有内容都注释掉,但没有解决.
In a default .Net Core project it works fine so it must be something in my project that changed along the way. I'm wondering where I need to start in order to debug this issue? I've tried commenting out almost everything in my Startup.csand Program.cs with no resolution.
推荐答案似乎在 ASP.NET Core 2.2 中进行了更改(我找不到关于此更改的任何公告).如果您没有在开发"环境中明确运行,则编译 Razor 视图,您将看不到对 .cshtml 进行的任何更改
There was a change made in ASP.NET Core 2.2 it seems (and I can't find any announcements about this change). If you are not explicitly running in the 'Development' environment then the Razor Views are compiled and you will not see any changes made to the .cshtml
但是,您可以使用 Startup 类中的一些配置关闭此功能,如下所示.
You can however turn off this using some config in your Startup class as follows.
services.AddMvc().AddRazorOptions(options => options.AllowRecompilingViewsOnFileChange = true);对于 ASP.NET Core 3.0 及更高版本,请参阅 Alexander Christov 的答案.
For ASP.NET Core 3.0 and higher, see Alexander Christov's answer.
更多推荐
.NET Core MVC 页面在更改后不刷新
发布评论