问题
I am using Visual Studio with ASP.NET Core and run the web site using just F5 or Ctrl+F5 (not using 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 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?
回答1:
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.
回答2:
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" } }
UPDATE: added "workingDirectory" and removed specific path. It's more generic now.
来源:https://stackoverflow.com/questions/40152854/how-to-watch-for-file-changes-dotnet-watch-with-visual-studio-asp-net-core