The accepted answer works, but it's 4+ years old. So here's how you make it work for Visual Studio 2019 (v16.8.5 in my case).
Inside the profiles
section of launchSettings.json
, you add a new profile, let's say "API Watch", with this content:
"API Watch": {
"commandName": "Executable",
"executablePath": "dotnet",
"commandLineArgs": "watch run",
"workingDirectory": "$(ProjectDir)",
"launchBrowser": true,
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"dotnetRunMessages": true
}
And then you go and select it in the Build profiles dropdown:

Now when you run it, regardless if with or without Debug mode on, the re-build and browser refresh (I use the Swagger UI as default page) happens automatically.
One note about using it in Debug mode, is that Visual Studio will mark the changes with green and will say that they won't be applied until a restart happens. I can confirm that this is not true and that the changes are really reflected by the auto rebuild feature of dotnet watch run
. It's just that VS 2019 gets confused and treats things from the old (standard) perspective.
