user3953989
user3953989

Reputation: 1929

Is live reload with in-process aspnet core 3 possible?

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

Upvotes: 23

Views: 19787

Answers (4)

SalkinD
SalkinD

Reputation: 783

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();

Upvotes: 0

iojancode
iojancode

Reputation: 618

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"

Upvotes: 9

Patrick Szalapski
Patrick Szalapski

Reputation: 9439

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

Upvotes: 8

Brando Zhang
Brando Zhang

Reputation: 28112

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();
}

Upvotes: 62

Related Questions