'Adding AddRazorRuntimeCompilation() to the container in .NET CORE 6 will break the CSS footer
I create a brand new ASP.NET Core MVC project using VS 2022 and .NET Core 6. VS will generate the base template and when I run it without touching any code, everything is fine.
So far so good.
Now I add the NuGet dependency Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation version 6.0.0.
In Program.cs file, I add a line
// Add services to the container.
builder.Services.AddControllersWithViews();
builder.Services.AddRazorPages().AddRazorRuntimeCompilation(); //Add this line of code
var app = builder.Build();
Rebuild the program and run it. Now I see the footer is not at the bottom of the page anymore.
Is it a bug or did I do something wrong here? Thanks.
Solution 1:[1]
I was struggling the same problem as well,
while trying the versions of Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation
nuget package and found the solution with 5.0.13 version.
If you downgrade the package from 6.0.1 to 5.0.13, the problem goes away and footer will be on bottom again.
Solution 2:[2]
Is it your intention to actually use RazorPages? It looks like you just want to add runtime compilation to the standard MVC views.
If you intend to use controllers and views, just add:
builder.Services.AddControllersWithViews().AddRazorRuntimeCompilation();
But, I tried your code as well and in my environment, the footer is present in both cases, even if I downgrade Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation from version 6.0.1 to 6.0.0.
Solution 3:[3]
I think there's no need to add the runtime compilation since in the newest update/version hot-reload has been officially released.
PS. I am currently following an asp.net tutorial and I encountered this problem. Here's the link: https://youtu.be/hZ1DASYd9rk
Solution 4:[4]
In Visual Studio 2022, there's an option for hot reload on file save
. this fixed my issue without having the need to install Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Hilmi Bilal Çam |
Solution 2 | R. Schreurs |
Solution 3 | I'm here to sleep |
Solution 4 | jellz77 |