.NET Hot Reload support for ASP.NET Core

.NET Hot Reload applies code changes, including changes to stylesheets, to a running app without restarting the app and without losing app state. Hot Reload is supported for all ASP.NET Core 6.0 and later projects.

Generally, updated code is rerun to take effect with the following conditions:

  • Some startup logic is only run once:
    • Middleware, unless the code update is to an inline middleware delegate.
    • Configured services.
    • Route creation and configuration, unless the code update is to a route handler delegate (for example, OnInitialized).
  • In Blazor apps, the framework triggers a Razor component render automatically.
  • In MVC and Razor Pages apps, Hot Reload triggers a browser refresh automatically.
  • Removing a Razor component parameter attribute doesn't cause the component to rerender. The app must be restarted.

For more information on supported scenarios, see Supported code changes (C# and Visual Basic).

Blazor WebAssembly

Blazor WebAssembly Hot Reload support has the following conditions:

  • Hot Reload reacts to most changes to method bodies, such as adding, removing, and editing variables, expressions, and statements.
  • Changes to the bodies of lambda expressions and local functions are also supported.
  • Adding new lambdas or local functions, adding a new await operator or yield keyword expression is not supported.
  • Changing the names of method parameters is not supported.
  • Changes outside of method bodies is not supported.

.NET CLI

Hot Reload is activated using the dotnet watch command:

dotnet watch

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.
  • No: Doesn't restart the app and leaves the app running without the changes applied.
  • Always: Restarts the app as needed when rude edits occur.
  • Never: Doesn't restart the app and avoids future prompts.

To disable support for Hot Reload, pass the --no-hot-reload option to the dotnet watch command:

dotnet watch --no-hot-reload

Disable Hot Reload

The following setting in Properties/launchSettings.json disables Hot Reload:

"hotReloadEnabled" : false

Additional resources

For more information, see the following resources in the Visual Studio documentation: