變量替換
Visual Studio Code在調(diào)試和任務(wù)配置文件以及某些選擇設(shè)置中支持變量替換钝吮。使用$ {variableName}語法在launch.json和task.json文件的鍵和值字符串內(nèi)部支持變量替換板辽。
預(yù)定義變量
- ${workspaceFolder} - 在VS Code中打開的文件夾的路徑
- ${workspaceFolderBasename} - VS Code中打開的文件夾名稱劲弦,不帶任何斜杠(/)
- ${file} - 當(dāng)前打開的文件
- ${relativeFile} - 當(dāng)前打開的相對(duì)于workspaceFolder的文件
- ${relativeFileDirname} - 當(dāng)前打開文件的目錄名(相對(duì)于workspaceFolder)
- ${fileBasename} - 當(dāng)前打開的文件的基本名稱
- ${fileBasenameNoExtension} - 當(dāng)前打開的文件基本名稱醇坝,不帶文件擴(kuò)展名
- ${fileDirname} - 當(dāng)前打開的文件的目錄名
- ${fileExtname} - 當(dāng)前打開文件的擴(kuò)展名
- ${cwd} - 啟動(dòng)時(shí)任務(wù)運(yùn)行程序的當(dāng)前工作目錄
- ${lineNumber} - 活動(dòng)文件中當(dāng)前選擇的行號(hào)
- ${selectedText} - 活動(dòng)文件中當(dāng)前選定的文本
- ${execPath} - VS Code可執(zhí)行文件的路徑
- ${defaultBuildTask} - 默認(rèn)構(gòu)建任務(wù)的名稱
例如:
Supposing that you have the following requirements:
- A file located at
/home/your-username/your-project/folder/file.ext
opened in your editor;- The directory
/home/your-username/your-project
opened as your root workspace.So you will have the following values for each variable:
- ${workspaceFolder} -
/home/your-username/your-project
- ${workspaceFolderBasename} -
your-project
- ${file} -
/home/your-username/your-project/folder/file.ext
- ${relativeFile} -
folder/file.ext
- ${relativeFileDirname} -
folder
- ${fileBasename} -
file.ext
- ${fileBasenameNoExtension} -
file
- ${fileDirname} -
/home/your-username/your-project/folder
- ${fileExtname} -
.ext
- ${lineNumber} - line number of the cursor
- ${selectedText} - text selected in your code editor
- ${execPath} - location of Code.exe