首页 > 解决方案 > VS Code Workspace 启动配置部分不起作用

问题描述

我的 VS Code 工作区文件包含启动配置和任务部分,因此开发人员可以在本地运行 Azure Functions。

但似乎工作区文件中的启动配置将被忽略。

如果我添加launch.jsontasks.json具有相同的内容,它可以正常工作。

.code-workspace

{
    "folders": [
        {
            "path": "."
        }
    ],
    "launch": {
        "configurations": [
            {
                "name": "Attach to .NET Functions",
                "type": "coreclr",
                "request": "attach",
                "processId": "${command:azureFunctions.pickProcess}"
            }
        ]
    },
    "tasks": {
        "version": "2.0.0",
        "tasks": [
            {
                "label": "clean",
                "command": "dotnet",
                "args": [
                    "clean",
                    "/property:GenerateFullPaths=true",
                    "/consoleloggerparameters:NoSummary"
                ],
                "type": "process",
                "problemMatcher": "$msCompile"
            },
            {
                "label": "build",
                "command": "dotnet",
                "args": [
                    "build",
                    "/property:GenerateFullPaths=true",
                    "/consoleloggerparameters:NoSummary"
                ],
                "type": "process",
                "dependsOn": "clean",
                "group": {
                    "kind": "build",
                    "isDefault": true
                },
                "problemMatcher": "$msCompile"
            },
            {
                "label": "clean release",
                "command": "dotnet",
                "args": [
                    "clean",
                    "--configuration",
                    "Release",
                    "/property:GenerateFullPaths=true",
                    "/consoleloggerparameters:NoSummary"
                ],
                "type": "process",
                "problemMatcher": "$msCompile"
            },
            {
                "label": "publish",
                "command": "dotnet",
                "args": [
                    "publish",
                    "--configuration",
                    "Release",
                    "/property:GenerateFullPaths=true",
                    "/consoleloggerparameters:NoSummary"
                ],
                "type": "process",
                "dependsOn": "clean release",
                "problemMatcher": "$msCompile"
            },
            {
                "type": "func",
                "dependsOn": "build",
                "options": {
                    "cwd": "${workspaceFolder}/src/ProjectAbc/bin/Debug/netcoreapp2.2"
                },
                "command": "host start",
                "isBackground": true,
                "problemMatcher": "$func-watch"
            }
        ]
    }
}

预期行为: 如果我按下F5工作区设置中的 lauch 配置,则应该使用它来构建和运行 Azure 功能。

实际行为: 如果我按F5VS Code 想要launch.json基于环境创建文件。

在此处输入图像描述

标签: visual-studio-codeazure-functionsvscode-settingsvscode-tasks

解决方案


I have reproduce your error,

This is the solution:

Please notice that Global launch configuration need you to add launch in user settings.

Have a look of this.

Your settings.json file should be like this:

{
    "azureFunctions.deploySubpath": ".",
    "azureFunctions.projectLanguage": "JavaScript",
    "azureFunctions.projectRuntime": "~2",
    "debug.internalConsoleOptions": "neverOpen",
    "azureFunctions.preDeployTask": "npm prune",

    "launch": {
        "version": "0.2.0",
        "configurations": [
        {
            "name": "Attach to Node Functions",
            "type": "node",
            "request": "launch",
            "port": 9229,
            "preLaunchTask": "func: host start",
            "outFiles": [
                "${workspaceRoot}/TimerTrigger/index.js"
            ]
        },
        {
            "type": "node",
            "request": "launch",
            "name": "Launch Program",
            "program": "${workspaceFolder}\\index.js"
        }
    ]
    }
        //---------------------------
"tasks":{
    "version": "2.0.0",
"tasks": {
    "version": "2.0.0",
    "tasks": [
        {
            "label": "clean",
            "command": "dotnet",
            "args": [
                "clean",
                "/property:GenerateFullPaths=true",
                "/consoleloggerparameters:NoSummary"
            ],
            "type": "process",
            "problemMatcher": "$msCompile"
        },
        {
            "label": "build",
            "command": "dotnet",
            "args": [
                "build",
                "/property:GenerateFullPaths=true",
                "/consoleloggerparameters:NoSummary"
            ],
            "type": "process",
            "dependsOn": "clean",
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "problemMatcher": "$msCompile"
        },
        {
            "label": "clean release",
            "command": "dotnet",
            "args": [
                "clean",
                "--configuration",
                "Release",
                "/property:GenerateFullPaths=true",
                "/consoleloggerparameters:NoSummary"
            ],
            "type": "process",
            "problemMatcher": "$msCompile"
        },
        {
            "label": "publish",
            "command": "dotnet",
            "args": [
                "publish",
                "--configuration",
                "Release",
                "/property:GenerateFullPaths=true",
                "/consoleloggerparameters:NoSummary"
            ],
            "type": "process",
            "dependsOn": "clean release",
            "problemMatcher": "$msCompile"
        },
        {
            "type": "func",
            "dependsOn": "build",
            "options": {
                "cwd": "${workspaceFolder}/src/ProjectAbc/bin/Debug/netcoreapp2.2"
            },
            "command": "host start",
            "isBackground": true,
            "problemMatcher": "$func-watch"
        }
    ]
    }
}
    }

Then you will never face that error. The VS Code will never try to create the launch.json file again.

Then It should work, please notice that your tasks configure is not correct! Your current problem comes from the tasks config not read by VSCode. Modify it and it should work fine.

enter image description here


推荐阅读