-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Description
I read this announcement about Razor runtime compilation now being obsolete: aspnet/Announcements#522
I then noticed in .NET 10, in a basic MVC application with Razor views, if you pass an options delegate to AddRazorRuntimeCompilation() in Program.cs, you will be shown a warning:
mvcBuilder.AddRazorRuntimeCompilation(delegate (MvcRazorRuntimeCompilationOptions options) { });
// ASPDEPR003: Razor runtime compilation is obsolete and is not recommended for production scenarios.
// For production scenarios, use the default build time compilation. For development scenarios, use
// Hot Reload instead. For more information, visit https://aka.ms/aspnet/deprecate/003.However, when you pass no argument to the method, it does not show a warning:
mvcBuilder.AddRazorRuntimeCompilation(); // no "obsolete" warning hereSo, is it just the first overload that's being obsoleted? Or, when you say "Razor runtime compilation is obsolete", does that mean that in the future we MUST use dotnet watch to run our MVC application, and classic Razor runtime compilation is being removed completely?
This is a problem for me, since in my development workflow, I do not want my entire application to get rebuilt every time I make a change to a Razor page. When I am running my application, and I make a change to a Razor page, I only want the Razor subsystem to recompile, not my entire application. I also do not want the web page to reload.
- When I make a change to a
.csfile, I don't want anything to happen. I will manually rebuild and restart the localhost server when I am done making changes. - When I make a change to a
.cshtmlfile, I only want the Razor subsystem to recompile, but only when I manually reload my page in the browser. Right now, with the Razor runtime recompilation, this works great--the Razor subsystem only recompiles my views when application tries to access one of them, for example when I reload the page (like a lazy-recompile).
Lastly, when I develop, I do not run my MVC application using Visual Studio, nor do I use the dotnet CLI. I run a separate instance of IIS Express that points to my application's DLL using a shortcut target:
Target: C:\Windows\System32\cmd.exe /c (set LAUNCHER_PATH=dotnet&&set LAUNCHER_ARGS=.\bin\Release\net10.0\MyProject.dll&&"C:\iisexpress\iisexpress.exe" /path:"C:\projects\example.com\MyProject" /port:8081 /trace:error)
This works great for me, because I can create a little icon on my desktop that runs my development server with a console window, with just a single mouse click. The current Razor runtime compilation feature works well with this setup.
In conclusion, what exactly is being removed from .NET regarding Razor runtime compilation, and will we be forced to use the dotnet watch command in the future if we want anything resembling Razor runtime recompilation? If we are forced to use the dotnet watch command going forward, how can I modify my shortcut target shown above to accommodate that?