Ask Learn Preview
Please sign in to use this experience.
Sign inThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Enhance your development workflow with the .NET CLI dotnet watch
command. Unlike the dotnet run
command, dotnet watch
automatically rebuilds and re-runs your application whenever you make changes to the source files. Additionally, dotnet watch
includes a hot reload feature, which injects updates directly to your running application without requiring a restart. dotnet watch
allows you to see the results of your changes faster, boosting productivity, and efficiency.
In this exercise, you will:
dotnet watch
command.dotnet watch
Run the web app using the dotnet watch
command from the command line:
In Visual Studio Code, if the integrated terminal pane isn't already available, select New Terminal from the Terminal menu to open the integrated terminal.
Build and Run the app with the following command:
dotnet watch
The project is built, run, and provides the ASP.NET Core app's endpoint URL on the command line:
Now listening on: http://localhost:5287
Since the port number in the URL provided is set randomly in configuration at project creation, your endpoint may have a different port number.
Open a browser to the URL generated at your own command line output, the app's response Hello World!
is displayed.
With the MyWebApp application still running and the browser still displaying the Hello World!
response:
app.MapGet
method so that it responds with "Hello .NET Developer Community!"
instead of "Hello World!"
.After saving the changes, dotnet watch
will automatically detect the modification to the Program.cs file. It will then:
dotnet watch
applies the changes to the running application without requiring a full rebuild when possible.dotnet watch
automatically rebuilds the application to incorporate the changes you made.dotnet watch
restarts the application.The output in the terminal indicates that the file Program.cs changed and the changes were hot reloaded into the running app.
To see the result of the change, refresh your browser. The updated response "Hello .NET Community!" is displayed.
This automatic rebuild and restart process allows you to quickly see the results of your changes without manually stopping and restarting the application.
Please sign in to use this experience.
Sign in