Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 481
user3953989 Avatar asked Oct 02 '19 14:10

user3953989


People also ask

How do I enable hot reload in .NET core?

To force the app to rebuild and restart, use the keyboard combination Ctrl + R in the command shell. When an unsupported code edit is made, called a rude edit, dotnet watch asks you if you want to restart the app: Yes: Restarts the app.

What is a hot reload in Visual Studio?

CSS Hot Reload: You can change CSS files while the app is running, and changes are applied immediately to the running app as you type. No Debugger: You get Hot Reload support when using Visual Studio to start your web app without the debugger (CTRL-F5).

How do I activate hot reload?

First, enable it in your IDE settings: On Windows, check the Enable XAML Hot Reload checkbox (and the required platforms) at Tools > Options > Debugging > Hot Reload. In earlier versions of Visual Studio 2019, the checkbox is at Tools > Options > Xamarin > Hot Reload.

What is hot reload?

Hot reloading allows you to see the changes that you have made in the code without reloading your entire app. Whenever you make any changes, all you need to do is save your code. As soon as you save your code, React Native tracks which files have changed since your last saved, and only reload those file for you.


3 Answers

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();
}
like image 79
Brando Zhang Avatar answered Oct 29 '22 13:10

Brando Zhang


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"
like image 35
Johann Medina Avatar answered Oct 29 '22 14:10

Johann Medina


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

like image 35
Patrick Szalapski Avatar answered Oct 29 '22 15:10

Patrick Szalapski