asp.net-corednxkestrel-http-server

How to watch for file changes "dotnet watch" with Visual Studio ASP.NET Core


I am using Visual Studio with ASP.NET Core and run the website using just F5 or Ctrl+F5 (not using the command line directly). I would like to use the "dotnet watch" functionality to make sure all changes are picked up on the fly to avoid starting the server again. It seems that with the command line you would use "dotnet watch run" for this, but Visual Studio uses launchSettings.json and does it behind the scenes if I understand it correctly.

How can I wire up "dotnet watch" there?


Solution

  • Open launchSettings.json and add this to profiles.

      "Watch": {
        "executablePath": "C:\\Program Files\\dotnet\\dotnet.exe",
        "commandLineArgs": "watch run",
        "launchBrowser": true,
        "launchUrl": "http://localhost:5000",
        "environmentVariables": {
          "ASPNETCORE_ENVIRONMENT": "Development"
        }
      }
    

    Open project.json and add this to tools.

    "Microsoft.DotNet.Watcher.Tools": "1.0.0-preview2-final"
    

    After restoring, we can Watch from within Visual Studio.

    enter image description here