Is it possible to change .cshtml View and see the changes instantly using .NET Core?

本秂侑毒 提交于 2019-12-01 08:01:23

This is something that is no longer enabled by default as of ASP.NET Core 3, but it can be re-enabled as documented here:

Runtime compilation is enabled using the Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation package. To enable runtime compilation, apps must:

  • Install the Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation NuGet package.
  • Update the project's Startup.ConfigureServices method to include a call to AddRazorRuntimeCompilation:

    services
          .AddControllersWithViews()
          .AddRazorRuntimeCompilation();
    

I've marked Kirk's answer as accepted, but maybe this experience could be useful also.

My goal was a "quick edit (cshtml/css/js/ts) then see" iteration.

No need to add and mod anything... I discovered that .NET Core (3) and VS 2019 is so much faster, so in case if we do not want to debug in VS (which is the scenario in most cases when we are changing cshtml/css/js/ts) there is really great iteration:

  1. Press ctrl+f5 to launch your web app (no debug) in browser
  2. See, test (debug js/ts in Chrome)
  3. Edit your cshtml/css/js/ts
  4. Press ctrl+shift+b to build (fast!)
  5. Switch to your browser and press ctrl+f5 to refresh your page (fast!)
  6. Goto 2
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!