debugging 配置launch.json和tasks.json以在Vscode中调试不同的C#项目

niwlg2el  于 2023-05-07  发布在  Vscode
关注(0)|答案(1)|浏览(206)

我刚开始学习如何在Vscode中使用C#,但无法生成Json文件来调试解决方案中的不同项目。
对于上下文,我有两个项目,Test 01和Test 02。Json文件看起来像这样:
Launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            // Use IntelliSense to find out which attributes exist for C# debugging
            // Use hover for the description of the existing attributes
            // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
            "name": ".NET Core Launch (console)",
            "type": "coreclr",
            "request": "launch",
            "preLaunchTask": "build",
            // If you have changed target frameworks, make sure to update the program path.
            "program": "${workspaceFolder}/Test01/bin/Debug/net7.0/Test01.dll",
            "args": [],
            "cwd": "${workspaceFolder}/Test01",
            // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
            "console": "internalConsole",
            "stopAtEntry": false
        },
        {
            "name": ".NET Core Attach",
            "type": "coreclr",
            "request": "attach"
        }
    ]
}

Tasks.json:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "command": "dotnet",
            "type": "process",
            "args": [
                "build",
                "${workspaceFolder}/Test01/Test01.csproj",
                "/property:GenerateFullPaths=true",
                "/consoleloggerparameters:NoSummary"
            ],
            "problemMatcher": "$msCompile"
        },
        {
            "label": "publish",
            "command": "dotnet",
            "type": "process",
            "args": [
                "publish",
                "${workspaceFolder}/Test01/Test01.csproj",
                "/property:GenerateFullPaths=true",
                "/consoleloggerparameters:NoSummary"
            ],
            "problemMatcher": "$msCompile"
        },
        {
            "label": "watch",
            "command": "dotnet",
            "type": "process",
            "args": [
                "watch",
                "run",
                "--project",
                "${workspaceFolder}/Test01/Test01.csproj"
            ],
            "problemMatcher": "$msCompile"
        }
    ]
}

我正在尝试配置vscode来开始学习C#,使用Vscode解决方案资源管理器扩展在同一个解决方案中添加多个项目,但是当我生成launch.json和tasks.json文件时,它们只添加了其中一个项目的路径。我应该创建多个发射/坦克配置(每个项目一个),还是有更好的解决方案?

pvcm50d1

pvcm50d11#

只需在各自的文件中复制现有的配置和任务。
Launch.json

{
"version": "0.2.0",
"configurations": [
    {
        "name": "Launch Test01",
        ...
        "preLaunchTask": "build Test01", 
        "program": "${workspaceFolder}/Test01/bin/Debug/net7.0/Test01.dll",
        "args": [],
        "cwd": "${workspaceFolder}/Test01",
        ...
    },
    {
        "name": "Launch Test02",
        ...
        "preLaunchTask": "build Test02", //match the tasks name from Tasks.json
        "program": "${workspaceFolder}/Test02/bin/Debug/net7.0/Test02.dll",
        "args": [],
        "cwd": "${workspaceFolder}/Test02",
        ...
    }
    ...
]
}

Tasks.json

{
"version": "2.0.0",
"tasks": [
    {
        "label": "build Test01",
        "command": "dotnet",
        "type": "process",
        "args": [
            "build",
            "${workspaceFolder}/Test01/Test01.csproj",
            "/property:GenerateFullPaths=true",
            "/consoleloggerparameters:NoSummary"
        ],
        "problemMatcher": "$msCompile"
    },
    {
        "label": "build Test02",
        "command": "dotnet",
        "type": "process",
        "args": [
            "build",
            "${workspaceFolder}/Test02/Test02.csproj",
            "/property:GenerateFullPaths=true",
            "/consoleloggerparameters:NoSummary"
        ],
        "problemMatcher": "$msCompile"
    },
    ...
]
}

相关问题