是否可以使用.NET Core更改.cshtml视图并立即查看更改? [英] Is it possible to change .cshtml View and see the changes instantly using .NET Core?
问题描述
上下文
在我的.NET Framework 4.x ASP.NET MVC项目中,使用Visual Studio IDE时,可以编辑.cshtml
视图,保存,然后按 ctrl + F5 并立即查看更改.
In my .NET Framework 4.x ASP.NET MVC projects, when using the Visual Studio IDE, it was possible to edit a .cshtml
view, save, then press ctrl+F5 in the browser and see the change immediately.
在ASP.NET Core应用程序(使用Visual Studio 2019和.NET Core 3 Preview 5)中,这似乎不再起作用.
This seems to be no longer work in ASP.NET Core applications (using Visual Studio 2019 and .NET Core 3 Preview 5).
问题
ASP.NET Core中缺少此功能吗?这是预览问题吗?还是我错过了什么?
Is this feature missing in ASP.NET Core? Is this a preview issue? Or am I missing something?
推荐答案
从ASP.NET Core 3开始,默认情况下 不再启用该功能,但可以将其重新启用在此处:
This is something that is no longer enabled by default as of ASP.NET Core 3, but it can be re-enabled as documented here:
使用
Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation
包启用运行时编译.要启用运行时编译,应用程序必须:
Runtime compilation is enabled using the
Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation
package. To enable runtime compilation, apps must:
- 安装 Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation NuGet程序包.
-
更新项目的
Startup.ConfigureServices
方法以包括对AddRazorRuntimeCompilation
的调用:
- Install the Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation NuGet package.
Update the project's
Startup.ConfigureServices
method to include a call toAddRazorRuntimeCompilation
:
services
.AddControllersWithViews()
.AddRazorRuntimeCompilation();
这篇关于是否可以使用.NET Core更改.cshtml视图并立即查看更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!