Lesson Weekend

When we make changes to a .NET application, these changes won't immediately be apparent in the browser. In order to show our updated application in the browser, we need to cycle the server.

There are two ways to do this. This is the more painful way:

  • Make sure updated code is saved in your code editor.

  • Navigate to the server window in the terminal and type in Ctrl + C. This quits the server.

  • Run dotnet run and navigate back to localhost:5000.

While this process works, it becomes very tedious to restart the server every time we make a change to our code.

Using a Watcher


Instead, it makes more sense to use a file watcher. A file watcher watches for changes and then automatically updates the server for us. There's no need to restart the server at all. To use a watcher we use the following command when we want to run the application:

$ dotnet watch run

Now every time we make a change, our server will automatically update. Note, however, that if you add or delete files or change the directory structure in any way, you will have to restart the server.

To learn more about watchers and the types of files we can watch, check out the documentation.

Use a file watcher so the server doesn't need to be restarted whenever code is changed:

$ dotnet watch run

Lesson 10 of 38
Last updated more than 3 months ago.