VisualStudio 代码任务和变量 [英] VisualStudio Code Tasks and Variables

查看:18
本文介绍了VisualStudio 代码任务和变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Visual Studio 2010 在创建外部工具以定义初始目录(如 $(ItemDir))时有一个选项,该目录将基于当前处于焦点的文件.我正在尝试在 Visual Studio 代码中做类似的事情,但我找不到等效的环境变量来做同样的事情.任何建议将不胜感激.

Visual studio 2010 had an option when creating external tools to define an initial directory like $(ItemDir) which would be based on the file currently in focus. I am trying to do something similar in visual studio code but I cannot find an equivalent environment variable to do the same thing. Any suggestions would be much appreciated.

推荐答案

只是为了将信息形式化为答案:

Just to formalize the info into an answer:

以下是可用于任务的预定义变量列表:变量参考

Here is a list of predefined variables that can be used in tasks: Variables reference

这里有更多关于在任务中使用变量的信息:变量替换

and here is more info on using variables in tasks : Variable substitution

从上面的最后一个链接来看,这真的很有趣:

And this is really interesting from the last link above:

同样,您可以通过以下方式引用您项目的配置设置在名称前加上 ${config:.

Similarly, you can reference your project's configuration settings by prefixing the name with ${config:.

例如,${config:python.pythonPath} 返回 Python 扩展设置python路径.

For example, ${config:python.pythonPath} returns the Python extension setting pythonPath.

以下是自定义任务配置的示例,其中使用您选择的项目在当前文件上执行 autopep8Python 可执行文件:

Below is an example of a custom task configuration which executes autopep8 on the current file using your project's selected Python executable:

{
        "label": "autopep8 current file",
        "type": "process",
        "command": "${config:python.pythonPath}",
        "args": [
            "-m",
            "autopep8",
            "-i",
            "${file}"
        ]
    }

从第一个链接我们看到您甚至可以将命令(如键绑定和命令面板中使用的那些)合并到您的任务中:

From the first link we see that you can even incorporate commands (like those used in keybindings and the command palette) into your tasks:

设置和命令变量

您可以参考 VS Code 设置和使用以下语法的命令:

You can reference VS Code settings and commands using the following syntax:

${config:Name} - 示例:${config:editor.fontSize}${command:CommandID} - 示例:${command:explorer.newFolder}

${config:Name} - example: ${config:editor.fontSize} ${command:CommandID} - example: ${command:explorer.newFolder}

最后,相关但因为有些人可能最终会在这里搜索这些,所以有一些变量可以在代码片段(但不是任务)中使用.请参阅代码段变量

Finally, related but because some people might end up here searching for these, there are variables that can be used in snippets (but not tasks). See Snippet Variables

这篇关于VisualStudio 代码任务和变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆