是否可以使用.NET Core更改.cshtml视图并立即查看更改? [英] Is it possible to change .cshtml View and see the changes instantly using .NET Core?

查看:346
本文介绍了是否可以使用.NET Core更改.cshtml视图并立即查看更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上下文

在我的.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:

  • Install the Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation NuGet package.
  • Update the project's Startup.ConfigureServices method to include a call to AddRazorRuntimeCompilation:

services
      .AddControllersWithViews()
      .AddRazorRuntimeCompilation();

这篇关于是否可以使用.NET Core更改.cshtml视图并立即查看更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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