.NET Core 3.0:Razor 视图不会在更改时自动重新编译 [英] .NET Core 3.0: Razor views don't automatically recompile on change

查看:31
本文介绍了.NET Core 3.0:Razor 视图不会在更改时自动重新编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据文档,默认情况下,Razor 视图应在 ASP.NET Core 3.0 的本地环境更改时重新编译.

According to the documentation, Razor views should, by default, recompile on change on local environments for ASP.NET Core 3.0.

但是,我的项目不在本地执行此操作.如果我在本地调试时更改视图并刷新,则不会反映更改.我必须停止解决方案,重新运行,然后才能看到变化.

However, my project doesn't do this locally. If I change a view and refresh when I'm debugging locally, the change is not reflected. I have to stop the solution, re-run, and then see the change.

我使用 Razor 页面在 Visual Studio 2019 上的默认 ASP.NET Core Web 应用程序模板和 ASP.NET Core 3.0.0 Preview 2 上执行此操作.知道我是否需要更改设置以启用此功能吗?

I am doing this on a default ASP.NET Core Web Application template on Visual Studio 2019 with ASP.NET Core 3.0.0 Preview 2 using Razor pages. Any idea if I need to change settings to enable this feature?

这个问题还是有很多意见的.引用了一些答案以补充

This question still gets a lot of views. A few answers have cited to add

services.AddControllersWithViews().AddRazorRuntimeCompilation(); 

添加 Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation NuGet 包后,到 Startup.cs 中的 ConfigureServices() 函数.就我而言,我只使用 Razor Pages,所以我不调用 AddControllersWithViews().相反,这对我有用:

To your ConfigureServices() function in Startup.cs after adding the Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation NuGet package. In my case, I am only using Razor Pages, so I don't call AddControllersWithViews(). Instead, this worked for me:

services.AddRazorPages().AddRazorRuntimeCompilation();

推荐答案

OK 好像还不支持 :(

OK it looks like it's not supported yet :(

运行时编译被删除 作为清理的结果ASP.NET Core 共享框架不依赖 Roslyn,支持页面和视图的运行时编译也已在此删除预览版.而是执行页面和视图的编译在构建时.在未来的预览更新中,我们将提供 NuGet用于可选地启用运行时编译支持的包应用程序.

Runtime compilation removed As a consequence of cleaning up the ASP.NET Core shared framework to not depend on Roslyn, support for runtime compilation of pages and views has also been removed in this preview release. Instead compilation of pages and views is performed at build time. In a future preview update we will provide a NuGet packages for optionally enabling runtime compilation support in an app.

您可以在此处阅读有关该问题的更多信息 https://github.com/aspnet/Announcements/问题/343

You can read more about the issue here https://github.com/aspnet/Announcements/issues/343

需要运行时编译或重新编译 Razor 文件的应用程序应该:

Applications that require runtime compilation or re-compilation of Razor files should:

  • 添加对 Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation 包的引用.它将作为 3.0.0-preview3 版本的一部分提供.
  • 更新应用程序的ConfigureServices 以包含对AddMvcRazorRuntimeCompilation 的调用:
  • Add a reference to the Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation package. It'll be available as part of the 3.0.0-preview3 release.
  • Update the application's ConfigureServices to include a call to AddMvcRazorRuntimeCompilation:

这篇关于.NET Core 3.0:Razor 视图不会在更改时自动重新编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆