当修改某些源代码文件时,我需要设置自动重启。
我正在将VS Code与Dotnet Core 3.1结合使用来开发Web API。
当调试开始时,我可以看到我的REST Api发布在http://localhost:5001/api/entities中,但是如果我更改模型或其他内容,则需要重新启动调试才能看到更改。
我已经尝试在终端上使用dotnet watch run
启动项目并尝试调试,但是我想知道是否有可能在项目中进行配置以在启用dotnet watch
的情况下启动所有调试。
是的,这完全有可能。
在VS Code中,打开您的tasks.json
,该文件应位于.vscode
文件夹中。在其中,您应该找到一个任务数组。
最简单的方法是简单地添加“监视”以仅编辑构建任务:
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"build",
"${workspaceFolder}/delete.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
}
]
由于“ build”是默认任务,因此在按F5键并进行startig调试时,它将始终在调试时启动dotnet start build。重点是将watch
添加到args数组中。
如果要为此执行一项专用任务,则可以在task.json中添加一个:
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"${workspaceFolder}/delete.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
}
并且在launch.json
中,您可以将此任务设置为preLaunchTask:
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "watch",
"program": "${workspaceFolder}/bin/Debug/netcoreapp3.0/delete.dll",
"args": [],
"cwd": "${workspaceFolder}",
"console": "internalConsole",
"stopAtEntry": false
}
]
我已经使用dotnet new console
创建了一个小型测试项目以在本地进行尝试,因此创建了delete.dll文件名。请根据需要进行修改。