title: Developing ASP.NET Core applications using dotnet watch
author: rick-anderson
ms.author: riande
manager: wpickett
ms.date: 10/14/2016
ms.topic: article
ms.assetid: 563ffb3f-d369-4aa5-bf0a-7300b4e7832c
ms.prod: aspnet-core
uid: tutorials/dotnet-watch
---
# Developing ASP.NET Core applications using dotnet watch
<aname=dotnet-watch></a>
By [Victor Hurdugaci](https://twitter.com/victorhurdugaci)
## Introduction
`dotnet watch` is a development time tool that runs a `dotnet` command when source files change. It can be used to compile, run tests, or publish when code changes.
In this tutorial we'll use an existing WebApi application that calculates the sum and product of two numbers to demonstrate the use cases of `dotnet watch`. The sample application contains an intentional bug that we'll fix as part of this tutorial.
Start by downloading [the sample application](https://github.com/aspnet/Docs/tree/master/aspnetcore/tutorials/dotnet-watch/sample). It contains two projects, `WebApp` (a web application) and `WebAppTests` (unit tests for the web application)
In a web browser, navigate to `http://localhost:5000/api/math/sum?a=4&b=5` and you should see the result `9`.
If you navigate to `http://localhost:5000/api/math/product?a=4&b=5` instead, you'd expect to get the result `20`. Instead, you get `9` again.
We'll fix that.
## Adding `dotnet watch` to a project
1. Add `Microsoft.DotNet.Watcher.Tools` to the `tools` section of the *WebApp/project.json* file.
2. Run `dotnet restore`.
The console output will show messages similar to the ones below:
````bash
log : Restoring packages for /Users/user/dev/aspnet/Docs/aspnet/tutorials/dotnet-watch/sample/WebApp/project.json...
log : Restoring packages for tool 'Microsoft.DotNet.Watcher.Tools' in /Users/user/dev/aspnet/Docs/aspnet/tutorials/dotnet-watch/sample/WebApp/project.json...
Any `dotnet` command can be run with `dotnet watch`: For example:
<!-- Command Command with watch dotnet run dotnet watch run dotnet run -f net451 dotnet watch run -f net451 dotnet run -f net451 ----arg1 dotnet watch run -f net451 ----arg1 dotnet test dotnet watch test -->
| Command | Command with watch |
| ---- | ----- |
| dotnet run | dotnet watch run |
| dotnet run -f net451 | dotnet watch run -f net451 |
| dotnet run -f net451 -- --arg1 | dotnet watch run -f net451 -- --arg1 |
| dotnet test | dotnet watch test |
To run `WebApp` using the watcher, run `dotnet watch run` in the `WebApp` folder. The console output will show messages similar to the ones below, indicating that `dotnet watch` is now watching code files:
````bash
user$ dotnet watch run
[DotNetWatcher] info: Running dotnet with the following arguments: run
[DotNetWatcher] info: dotnet process id: 39746
Project WebApp (.NETCoreApp,Version=v1.0) was previously compiled. Skipping compilation.
Save the file. The console output will show messages similar to the ones below, indicating that `dotnet watch` detected a file change and restarted the application.
[DotNetWatcher] info: Waiting for a file to change before restarting dotnet...
````
Once all the tests run, the watcher will indicate that it's waiting for a file to change before restarting `dotnet test`.
3. Open the controller file in *WebApp/Controllers/MathController.cs* and change some code. If you haven't fixed the product bug, do it now. Save the file.
`dotnet watch` will detect the file change and rerun the tests. The console output will show messages similar to the one below: