簡體   English   中英

我可以從 VSC 中的 tasks.json 訪問其他 json 文件中定義的設置嗎?

[英]Can I access settings defined in other json files from tasks.json in VSC?

我想在 VSC 中創建 tasks.json 文件。 我知道如何訪問預定義變量、環境變量、配置變量……這在 變量參考頁面中都有很好的解釋。 但是我在我的項目中的另一個 json 文件中有一些配置 - 有沒有辦法訪問它們? 暫時我只是將我需要的設置復制到 settings.json - 所以我可以像訪問任何其他配置變量一樣訪問它們 - 但這看起來不正確。 這就是我的意思:我將以下內容添加到 settings.json

"tq.appName" : "App Name",
"tq.appPublisher" : "Pub Name",
"tq.appVersion" : "1111111111",
"tq.targetDockerContainerName": "docker"

然后我可以在我的任務中訪問它們:

        "label": "Build APP and replace/publish in docker image",
        "type": "shell",
        "command": "${workspaceFolder}\\.vscode\\DevelopingDaily.ps1",
        "args": [
            {
                "value": "${config:tq.appName}",
                "quoting": "strong"
            },
            {
                "value": "${config:tq.targetDockerContainerName}",
                "quoting": "strong"
            },
            {
                "value": "${workspaceFolder}\\${config:tq.appPublisher}_${config:tq.appName}_${config:tq.appVersion}.app",
                "quoting": "strong"
            }
        ]

但是這些值存儲在項目中的 app.json 文件中 - 而不是在 settings.json 中。 我寧願直接從 app.json 獲取值 - 無需將它們復制到設置中......可能嗎?

您可以使用擴展命令變量命令extension.commandvariable.file.content

使用config.json文件

{
  "log": "foobar.log",
  "server1": {
    "port": 5011
  },
  "server2": {
    "port": 5023
  }
}

在你的 tasks.json 你想使用 server1 端口值。

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "echo Server1Port",
      "type": "shell",
      "command": "echo",
      "args": [
        "${input:configServer1Port}"
      ],
      "problemMatcher": []
    }
  ],
  "inputs": [
    {
      "id": "configServer1Port",
      "type": "command",
      "command": "extension.commandvariable.file.content",
      "args": {
        "fileName": "${workspaceFolder}/config.json",
        "json": "content.server1.port",
        "default": "4321"
      }
    }
  ]
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM