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

4

23

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

Clamshell answered 2/10, 2019 at 14:35 Comment(0)
C
62

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();
}
Ceramist answered 3/10, 2019 at 2:43 Comment(6)
This was it! Thanks Brando!Clamshell
Works for MVC as well.Suellensuelo
Worked as expecting. Thank youGaribull
Like a charm, thank you!Honorific
An important note... when I use Hot Reload with IIS, I have to manually refresh the browser after the Hot Reload, where IIS Express refreshes automatically.Parodist
With dotnet 3.1 you'll additionally need to add <PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="3.1.3" /> to your csproj.Spearhead
D
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"
Druid answered 13/6, 2020 at 17:13 Comment(0)
P
8

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

Particular answered 21/2, 2020 at 0:54 Comment(2)
Yes, finally something that works and easy! You shoulld add to your answer the mains steps to do so in case the link goes offPigpen
I added a link to the actual package. If that goes down, then we probably shouldn't use this anyway.Particular
S
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();
Spearhead answered 1/6, 2022 at 8:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.