22

I recently upgraded an .Net Framwork AspNet MVC app to a AspNet Core 3 MVC app and I'd like the ability to change a view, save, and refresh my browser window to see the changes. Now it appears I have to do a build every time before I can see any changes. Is there a way to change this behavior?

This is being hosted under IIS 10

user3953989
  • 1,844
  • 3
  • 25
  • 56

4 Answers4

61

As far as I know, the runtime compilation could just work in the develop environment. That means you couldn't use it in the production environment(which is hosted on the IIS).

If you change the visual studio's debug environment to IIS, it will stil work.

Besides, RuntimeCompilation is not a build-in feature in the asp.net core 3.0.

If you want to use it, I suggest you could try to install the package Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation and then configure AddRazorRuntimeCompilation in Startup.cs like

public void ConfigureServices(IServiceCollection services)
{
    services.AddControllersWithViews().AddRazorRuntimeCompilation();
}
Brando Zhang
  • 22,586
  • 6
  • 37
  • 65
9

There is a new way of doing this for 3.1, taken from: https://learn.microsoft.com/en-us/aspnet/core/mvc/views/view-compilation?view=aspnetcore-3.1

Add the package at csproj

<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="3.1.3" />

Then at launch.json, add a new environment variable

"ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation"
iojancode
  • 610
  • 6
  • 7
8

I was very happy to implement Westwind.AspnetCore.LiveReload per this blog post. It was quite easy and worked better than BrowserSync.

Patrick Szalapski
  • 8,738
  • 11
  • 67
  • 129
  • 1
    Yes, finally something that works and easy! You shoulld add to your answer the mains steps to do so in case the link goes off – Daniel Apr 06 '20 at 21:19
  • 1
    I added a link to the actual package. If that goes down, then we probably shouldn't use this anyway. – Patrick Szalapski Apr 08 '20 at 18:07
0

After some search I found a very simple solution:

Add following reference to csproj:

<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="3.1.3" />

Add AddRazorRuntimeCompilation() to your services configuration

services.AddControllersWithViews().AddRazorRuntimeCompilation();
SalkinD
  • 753
  • 9
  • 23