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

查看:43
本文介绍了.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页面在带有ASP.NET Core 3.0.0 Preview 2的Visual Studio 2019上的默认ASP.NET Core Web应用程序模板上执行此操作.我是否需要更改设置以启用此功能?

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 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/了解更多信息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天全站免登陆