liveBook · Manning

Dotnet watch

As explained in Pro ASP.NET Core 7, Tenth Edition

dotnet watch is a .NET command-line tool that monitors source files and reruns or rebuilds an application when changes occur.

dotnet watch builds and runs a .NET application, monitors project files, and applies supported changes through hot reload. In ASP.NET Core development, it keeps the browser synchronized without repeatedly stopping the application and running dotnet run. section 4.3.1 section 4.6

A practical development loop looks like this:

  • Run dotnet watch from the project directory; the command starts the application and can open a browser window. section 3.2.1 section 4.3.1
  • Edit a view, HTML file, or other supported project file and save it; dotnet watch recompiles the project and reloads the browser. section 3.2.1 section 4.3.1
  • Expect a restart prompt when an edit cannot be applied as hot reload; choose restart, or select Always when repeated unsupported edits are expected. section 4.3.1 section 21.1.2
  • Use dotnet run instead when changing initial service or middleware configuration or routing, because those changes are not handled reliably by dotnet watch. section 23.1.1

Editing a view without restarting

In a PartyInvites ASP.NET Core project, run dotnet watch, open the application, and change Views/Home/Index.cshtml. The updated party message appears in the browser automatically. Similarly, changing wwwroot/demo.html triggers recompilation and a browser update. If changing a C# namespace produces “Unable to apply hot reload because of a rude edit,” restart the application. section 3.2.1 section 4.3.1

Listing 4.8 Starting the application with hot reload
dotnet watch

Shows the complete command used to start an ASP.NET Core application with hot reload. section 4.3.1

How Pro ASP.NET Core 7, Tenth Edition covers it

How deep it goes
Explains startup, browser reloading, and restart fallbacks, but stops short of describing hot reload internals.
Examples
Uses PartyInvites views, wwwroot HTML, API application startup, and C# namespace edits to demonstrate reloads and failures.
What it assumes
Assumes an existing ASP.NET Core project and command prompt, while demonstrating the dotnet watch command from zero.
What you can do after
Operate a development application with automatic browser updates and choose when unsupported edits require an application restart.
How it connects
Connects hot reload with ASP.NET Core, dotnet run, browser reloads, Razor Pages, views, and application routing.

Also explained in

Compare how 2 books explain dotnet watch →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Pro ASP.NET Core 7, Tenth Edition. The section links point to the parts of the book it draws on.