VSCode调试设置
Posted chester.chen
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了VSCode调试设置相关的知识,希望对你有一定的参考价值。
tasks.json
{ "version": "0.1.0", "isShellCommand": true, "args": [], "tasks": [ { "taskName": "build_console", "command":"dotnet" "args": [ "build", //组成dotnet build //设置需要编译的项目,如果存在多个启动项目可以设置成解决方案文件(.sln),这里只有一个项目所以设置运行项目也可以 "${workspaceRoot}\\\\VSCodeTutorial.ConsoleApp\\\\VSCodeTutorial.ConsoleApp.csproj" ], "isBuildCommand": true, //设置是否编译项目 "problemMatcher": "$msCompile" }, { "taskName": "UnitTest", "command":"dotnet", "args": [ "test",//组成dotnet test 命令 "${workspaceRoot}\\\\VSCodeTutorial.UnitTest\\\\VSCodeTutorial.UnitTest.csproj" ], "isTestCommand": true,//设置为单元测试项目 "problemMatcher": "$msCompile" } ] }
{ "version": "0.1.0", "command": "dotnet", //全局命令,即所有的任务都使用这个命令,也可以在各个任务中设置 "isShellCommand": true, "args": [], "tasks": [ { "taskName": "build", //任务名称 当设置了主的command 之后这个taskName也会作为一个命令参数 "args": [ "${workspaceRoot}\\\\VSCodeTutorial.ConsoleApp\\\\VSCodeTutorial.ConsoleApp.csproj" ], "isBuildCommand": true, //一个解决方案只能设置一个编译任务,多设置了也是白搭,当然也能执行,只是不能利用快捷方式运行了 "problemMatcher": "$msCompile"//C#项目的problemMatcher } ] }
tasks.json文件是项目任务的配置文件,可在launch.json文件中配置要执行的task。示例如下:
{ "version": "0.2.0", "configurations": [ { "name": ".NET Core Launch (console)", //配置名称 可以改成更好识别的名字 "type": "coreclr", // .net core类型的调试 "request": "launch", //调试方式 不用改 "preLaunchTask": "build", // 前置任务,这里是编译,但是默认的编译任务,已经被我改了名字了,所以这里要改一下哦 "program": "${workspaceRoot}\\\\VSCodeTutorial.ConsoleApp\\\\bin\\\\Debug\\\\netcoreapp1.1\\\\VSCodeTutorial.ConsoleApp.dll", //需要调试的DLL的位置 "args": [], //额外的参数 "cwd": "${workspaceRoot}\\\\VSCodeTutorial.ConsoleApp", //工作目录 "console": "internalConsole", //控制台模式,这里是内嵌控制台,一会要改成外置的,不然没法交互输入 "stopAtEntry": false, "internalConsoleOptions": "openOnSessionStart" }, { "name": ".NET Core Attach", //名称 "type": "coreclr", //类型 "request": "attach", //使用附加的方式 "processId": "${command:pickProcess}" //附加的进程ID } ] }
{ "version": "0.2.0", "configurations": [ { "name": "调试ConsoleApp", //修改下命令 "type": "coreclr", "request": "launch", "preLaunchTask": "build_console", //修改前置任务名和task.json中配置一致 "program": "${workspaceRoot}\\\\VSCodeTutorial.ConsoleApp\\\\bin\\\\Debug\\\\netcoreapp1.1\\\\VSCodeTutorial.ConsoleApp.dll", "args": [], "cwd": "${workspaceRoot}\\\\VSCodeTutorial.ConsoleApp", "externalConsole":true, //使用外置的控制台 "stopAtEntry": false, "internalConsoleOptions": "openOnSessionStart" }, { "name": ".NET Core Attach", "type": "coreclr", "request": "attach", "processId": "${command:pickProcess}" } ] }
{ "version": "0.2.0", "configurations": [ "HelloRpcClientLaunch" { "name": "HelloRpcServer", "type": "coreclr", "request": "launch", "preLaunchTask": "buildServer", "program": "${workspaceRoot}\\\\src\\\\sample\\\\HelloRpc\\\\HelloRpc.Server\\\\bin\\\\Debug\\\\netcoreapp1.1\\\\HelloRpc.Server.dll", "args": [], "cwd": "${workspaceRoot}\\\\src\\\\sample\\\\HelloRpc\\\\HelloRpc.Server", "externalConsole":true, "stopAtEntry": false, "internalConsoleOptions": "openOnSessionStart" }, "HelloRpcClientLaunch" { "name": "HelloRpcClient", "type": "coreclr", "request": "launch", "preLaunchTask": "buildClient", "program": "${workspaceRoot}\\\\src\\\\sample\\\\HelloRpc\\\\HelloRpc.Client\\\\bin\\\\Debug\\\\netcoreapp1.1\\\\HelloRpc.Client.dll", "args": [], "cwd": "${workspaceRoot}\\\\src\\\\sample\\\\HelloRpc\\\\HelloRpc.Client", "externalConsole":true, "stopAtEntry": false, "internalConsoleOptions": "openOnSessionStart" } ] "compounds": [ { "name": "Server/Client", "configurations": ["HelloRpcServer", "HelloRpcClient"] } ] }
引用文章:https://www.cnblogs.com/Leo_wl/p/6732242.html
总结:
launch.json文件:调试配置
tasks.json:任务配置
以上是关于VSCode调试设置的主要内容,如果未能解决你的问题,请参考以下文章