Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
425 views
in Technique[技术] by (71.8m points)

asp.net core mvc - Why do I need to enable razor runtime compile? Am I taking crazy pills?

As far as I know I've always been able to update cshtml files and immediately see changes (upon refreshing browser) without having to stop my project.

But as I am creating a new project I see this new option to enable this feature and I'm wondering what it is because, after all, I've always been able to do this. But as far as I can tell it does exactly what it says... as if I wasn't able to do this in the past?

But I also notice now that when I make a change to a razor page, it takes a looot longer to see the update as Visual Studio recompiles the project.

What... is... going... on?

question from:https://stackoverflow.com/questions/65928670/why-do-i-need-to-enable-razor-runtime-compile-am-i-taking-crazy-pills

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

As far as I know I've always been able to update cshtml files and immediately see changes (upon refreshing browser) without having to stop my project.

Yes.Before asp.net core 3.0,you could do it by default.After asp.net core 3.0,you could install the Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation NuGet package to enable runtime compilation.

1.Install the Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation NuGet package.

2.Update the project's Startup.ConfigureServices method to include a call to AddRazorRuntimeCompilation:

services.AddControllersWithViews().AddRazorRuntimeCompilation();

Reference:

https://docs.microsoft.com/en-us/aspnet/core/mvc/views/view-compilation?view=aspnetcore-5.0&tabs=visual-studio#enable-runtime-compilation-in-an-existing-project

Update:

From asp.net core 3.1,you could select the Enable Razor runtime compilation checkbox in the Create a new ASP.NET Core web application dialog:

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...