如何使用Visual Studio ASP.NET Core观察文件更改“dotnet watch”

问题描述 投票:10回答:2

我使用Visual Studio与ASP.NET Core并使用F5或Ctrl + F5(不直接使用命令行)运行网站。我想使用“dotnet watch”功能来确保动态获取所有更改以避免再次启动服务器。似乎使用命令行你会使用“dotnet watch run”,但Visual Studio使用launchSettings.json并在幕后操作,如果我理解正确的话。

如何在那里连接“dotnet手表”?

asp.net-core dnx kestrel-http-server
2个回答
17
投票

打开launchSettings.json并将其添加到profiles

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

打开project.json并将其添加到tools

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

恢复后,我们可以在Visual Studio中观看。

enter image description here


7
投票

如果要使用ASP.NET 2.x或3.x,则需要稍微更改一下。

  • 监视工具现在是一个全局工具,您无需再将其添加为参考
  • 语法略有不同 “Watch”:{“executablePath”:“dotnet.exe”,“workingDirectory”:“$(ProjectDir)”,“commandLineArgs”:“watch run”,“launchBrowser”:true,“launchUrl”:“http:// localhost:5000 /“,”environmentVariables“:{”ASPNETCORE_ENVIRONMENT“:”开发“}}

更新:添加“workingDirectory”并删除特定路径。它现在更通用了。

© www.soinside.com 2019 - 2024. All rights reserved.