【问题标题】:Auto-create the task's CWD folder with Visual Studio Code使用 Visual Studio Code 自动创建任务的 CWD 文件夹
【发布时间】:2020-01-11 21:22:34
【问题描述】:

我正在创建一个 C++ 项目,使用 Visual Studio Code 作为我的 IDE,cmake 作为我的构建工具链。使用“官方”CMake Tools,我可以进行“in-tree”编译:

myComplexProjectName/
  include/
  src/
  build/ <--Created by CMake

但是,我想像这样进行树外编译:

~/Documents/
  Projets/
    ...
      myComplexProjectName/
  builds/
    myComplexProjectName/

~/Documents/builds/ 文件夹已存在。

我正在尝试使用 Visual Studio Code 的任务来实现此配置。我尝试了以下tasks.json 配置:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Build Cpp CAN Parser static library",
            "type": "shell",
            "command": "cmake",
            "args": [
                "${workspaceFolder}"
            ],
            "options": {
                "cwd": "~/Documents/builds/${workspaceFolderBasename}/"
            },
            "group": "build",
            "presentation": {
                // Reveal the output only if unrecognized errors occur.
                "reveal": "silent"
            },
            // Use the standard MS compiler pattern to detect errors, warnings and infos
            "problemMatcher": "$gcc"
        }
    ]
}

我得到以下错误:

> Executing task: cmake /home/<username>/Documents/Projets/CAN/myComplexProjectName <

The terminal shell CWD "/home/<username>/Documents/Projets/CAN/myComplexProjectName/~/Documents/builds/myComplexProjectName/" does not exist

显然我可以自己创建输出文件夹,但有没有办法可以在任务运行之前自动创建文件夹?

【问题讨论】:

    标签: visual-studio-code cmake


    【解决方案1】:

    您可以设置对任务的依赖来构建文件夹,这就是我正在使用的

    {
        "version": "2.0.0",
        "tasks": [
            {
                "label": "Test",
                "type": "shell",
                "dependsOn": "_makebuildfolder",
                "options": {
                  "cwd": "${workspaceFolder}/work/test/build"
                },
                "command": "pwd",
                "problemMatcher": [],
                "group": {
                    "kind": "test",
                    "isDefault": true
                }
            },
            {
              "label": "_makebuildfolder",
              "type": "shell",
              "command": "mkdir -p ${workspaceFolder}/work/test/build",
              "problemMatcher": [],
              "group": "none"
            }
        ]
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-27
      • 1970-01-01
      • 2016-05-24
      • 1970-01-01
      • 2018-03-07
      • 2023-03-10
      相关资源
      最近更新 更多