我是靠谱客的博主 无聊自行车,最近开发中收集的这篇文章主要介绍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:任务配置

 

转载于:https://www.cnblogs.com/chenyishi/p/8416566.html

最后

以上就是无聊自行车为你收集整理的VSCode调试设置的全部内容,希望文章能够帮你解决VSCode调试设置所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(41)

评论列表共有 0 条评论

立即
投稿
返回
顶部