【问题标题】:Define a task property as one that can change per platform将任务属性定义为可以根据平台更改的属性
【发布时间】:2020-02-24 21:06:50
【问题描述】:

我正在开发一个provide tasks 的 VSCode 扩展,我如何指定一个属性可以根据平台更改,例如在“shell”任务中我们可以拥有这个tasks.json

"tasks": [
{
    "type": "shell",
    "windows": { "command": "wndCmd.exe" },
    "linux": { "command": "lnxCmd" },
    "osx": { "command": "osxCmd" }
}]

但对我来说这是不可能的。

从文档示例中,不可能创建如下任务:

"tasks": [
{
    "type": "rake",
    "task": "some",
    "windows": { "file": "winFile" },
    "linux": { "file": "linuxFile" },
    "osx": { "file": "osxFile" }
}]

【问题讨论】:

    标签: visual-studio-code vscode-extensions vscode-tasks


    【解决方案1】:

    我真的不明白为什么您需要对动态生成的任务执行此操作,这只对声明性/静态任务声明有意义。

    只需生成适合当前操作系统的任务版本。您可以查看process.platform ,另请参阅:

    【讨论】:

    • 我的任务是一个外部构建系统的包装器,所以我想允许用户为不同的平台设置不同的选项,它不是那么外星......
    • 生成的任务没有“设置选项”之类的东西。 github.com/microsoft/vscode/issues/58836
    • 想着想着我明白我可以简单地用手做...
    【解决方案2】:

    我可以手动完成:

    "taskDefinitions": [
        {
            "type": "rake",
            "required": [
                "task"
            ],
            "properties": {
                "task": {
                    "type": "string",
                    "description": "The Rake task to customize"
                },
                "file": {
                    "type": "string",
                    "description": "The Rake file that provides the task. Can be omitted."
                },
                "windows: {
                    "type": "object",
                    "properties": {
                        "file": {
                            "type": "string",
                            "description": "..."
                        }
                    }
                },
                "linux: {
                    "type": "object",
                    "properties": {
                        "file": {
                            "type": "string",
                            "description": "..."
                        }
                    }
                },
                "osx: {
                    "type": "object",
                    "properties": {
                        "file": {
                            "type": "string",
                            "description": "..."
                        }
                    }
                }
            }
        }
    ]
    

    【讨论】:

    • 我不确定它是否符合您的想法。这些只是“识别”生成任务的属性,用户无法配置它们。另请参阅我之前链接的那个问题。
    • 这段代码已经过测试,可以正常工作github.com/APerricone/harbourCodeExtension/blob/…
    猜你喜欢
    • 2013-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-13
    • 2023-03-08
    • 2016-04-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多