【问题标题】:Adding AddRazorRuntimeCompilation() to the container in .NET CORE 6 will break the CSS footer将 AddRazorRuntimeCompilation() 添加到 .NET CORE 6 中的容器将破坏 CSS 页脚
【发布时间】:2021-12-07 09:11:01
【问题描述】:

我使用 VS 2022 和 .NET Core 6 创建了一个全新的 ASP.NET Core MVC 项目。 VS 将生成基本模板,当我运行它而不接触任何代码时,一切都很好。

到目前为止一切顺利。

现在我添加 NuGet 依赖项 Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation 版本 6.0.0。

Program.cs文件中,我添加了一行

// Add services to the container.
builder.Services.AddControllersWithViews();
builder.Services.AddRazorPages().AddRazorRuntimeCompilation(); //Add this line of code
var app = builder.Build();

重建程序并运行它。现在我看到页脚不再位于页面底部了。

这是一个错误还是我在这里做错了什么?谢谢。

【问题讨论】:

  • 本地开发环境有这个问题吗?
  • 是的,它在本地环境(localhost)中。

标签: asp.net-core asp.net-core-mvc asp.net-core-6.0


【解决方案1】:

您是否打算实际使用RazorPages?看起来您只想将运行时编译添加到标准 MVC 视图中。

如果您打算使用控制器和视图,只需添加:

builder.Services.AddControllersWithViews().AddRazorRuntimeCompilation();

但是,我也尝试了您的代码,并且在我的环境中,即使我将 Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation 从版本 6.0.1 降级到 6.0.0,页脚在这两种情况下都存在。

【讨论】:

    【解决方案2】:

    我也遇到了同样的问题,
    在尝试 Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation nuget 包的版本时,找到了 5.0.13 版本的解决方案。

    如果您将软件包从 6.0.1 降级到 5.0.13,问题就会消失,页脚将再次出现在底部。

    【讨论】:

      猜你喜欢
      • 2022-12-30
      • 1970-01-01
      • 2020-10-04
      • 2012-03-04
      • 2021-10-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-31
      相关资源
      最近更新 更多