Is it possible to change .cshtml View and see the

2020-03-24 06:57发布

Context

In my NET Framework 4.x ASP MVC projects, when using the IDE, it was possible to edit a .cshtml View, then save, then press ctrl+F5 in the browser and see the actual change.

It seems to be not working in .NET Core (using VS 2019 and .NET Core 3 Preview 5)

Question

Is this feature missing in .NET Core or is this a preview issue, or am I missing something?

2条回答
趁早两清
2楼-- · 2020-03-24 07:09

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
查看更多
姐就是有狂的资本
3楼-- · 2020-03-24 07:31

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();
    
查看更多
登录 后发表回答