gpt4 book ai didi

c# - .NET核心3.0 : Razor views don't automatically recompile on change

转载 作者:行者123 更新时间:2023-12-02 16:12:46 24 4
gpt4 key购买 nike

根据the documentation默认情况下,Razor View 应根据 ASP.NET Core 3.0 本地环境的更改重新编译。

但是,我的项目并没有在本地执行此操作。如果我在本地调试时更改 View 并刷新,则不会反射(reflect)更改。我必须停止解决方案,重新运行,然后查看更改。

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

最佳答案

对于 ASP.NET Core 3 发行版本:

   services.AddControllersWithViews().AddRazorRuntimeCompilation();

https://learn.microsoft.com/en-us/aspnet/core/mvc/views/view-compilation?view=aspnetcore-3.0

它也可以有条件地仅针对本地开发启用,引用自链接:

Runtime compilation can be enabled such that it's only available forlocal development. Conditionally enabling in this manner ensures thatthe published output:

Uses compiled views.
Is smaller in size.
Doesn't enable file watchersin production.

   public Startup(IConfiguration configuration, IWebHostEnvironment env)
{
Configuration = configuration;
Env = env;
}

public IWebHostEnvironment Env { get; set; }
public IConfiguration Configuration { get; }

public void ConfigureServices(IServiceCollection services)
{
IMvcBuilder builder = services.AddRazorPages();

#if DEBUG
if (Env.IsDevelopment())
{
builder.AddRazorRuntimeCompilation();
}
#endif
}

关于c# - .NET核心3.0 : Razor views don't automatically recompile on change,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54600273/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com