If you want to use ASP.NET 2.x or 3.x you need to change it a bit.
The watch tool is a global tool now and you don't need to add it as a reference any longer
The syntax is slightly different
"Watch": {
"executablePath": "dotnet.exe",
"workingDirectory": "$(ProjectDir)",
"commandLineArgs": "watch run",
"launchBrowser": true,
"launchUrl": "http://localhost:5000/",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
For .Net 5 & 6
In VisualStudio 2019
- Go to Tools > ⚙ Options > Projects and Solutions > ASP .NET Core
- Select Auto build and refresh browser after saving changes in Auto build and refresh option
- Press Ctrl + F5 (Start Without Debugging) IMPORTANT: Only works if run without debbuging
Otherwise add this to your launchSettings.json
:
{
"iisSettings": {
...
},
"profiles": {
... ,
"Watch": {
"commandName": "Executable",
"executablePath": "dotnet.exe",
"workingDirectory": "$(ProjectDir)",
"commandLineArgs": "watch run"
}
}
}
The automatically generated profile
with "commandName":"Project"
has all the other properties needed: launchBrowser
, applicationUrl
, environmentVariables
, dotnetRunMessages
and hotReloadProfile
. Any modifications should be made there.
Corresponding Blog-Post from Juan Cruz Fiant: https://dev.to/juxant/auto-refresh-with-dotnet-watch-for-asp-net-core-projects-20no
For .Net 8 (with https
and app.useHsts
)
TLDR;
Move the https
profile to the top
Add "ASPNETCORE_HTTPS_PORT": "7186"
to the environment variables section for the https
profile
Add
"Watch": {
"commandName": "Executable",
"executablePath": "dotnet.exe",
"workingDirectory": "$(ProjectDir)",
"commandLineArgs": "watch --non-interactive run",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"ASPNETCORE_HTTPS_PORT": "7186"
},
"dotnetRunMessages": true,
"applicationUrl": "https://localhost:7186;http://localhost:5274"
},
Things have changed. Visual Studio puts many different Profiles into your launchsettings.json
, especially when using https
and app.UseHsts
.
First I had to move the https
profile on top, as the first profile!
Under "environmentVariables"
I needed to add "ASPNETCORE_HTTPS_PORT": "7186"
to make it work with lauchbrowser
and the HTTPS redirect.
I added --non-interactive
to force watch
to restart the app if it can't hot reload and stops asking me.
My complete launchsettings.json
{
"profiles": {
"https": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"ASPNETCORE_HTTPS_PORT": "7186"
},
"dotnetRunMessages": true,
"applicationUrl": "https://localhost:7186;http://localhost:5274"
},
"http": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
},
"dotnetRunMessages": true,
"applicationUrl": "http://localhost:5274"
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
}
},
"Watch": {
"commandName": "Executable",
"executablePath": "dotnet.exe",
"workingDirectory": "$(ProjectDir)",
"commandLineArgs": "watch --non-interactive run",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"ASPNETCORE_HTTPS_PORT": "7186"
},
"dotnetRunMessages": true,
"applicationUrl": "https://localhost:7186;http://localhost:5274"
},
"WSL": {
"commandName": "WSL2",
"launchBrowser": true,
"launchUrl": "https://localhost:7186",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"ASPNETCORE_URLS": "https://localhost:7186;http://localhost:5274",
"ASPNETCORE_HTTPS_PORT": "7186"
},
"distributionName": ""
}
},
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:60552",
"sslPort": 44360
}
}
If you start watch from the command line, it seems to use the default profile -> the first profile in the list.
If you want to explicitly start the Watch
profile from the command-line, use this syntax:
dotnet watch --non-interactive --launch-profile "Watch" --project INSERT_PATH_TO_PROJECT