两周前我下载了Visual Studio Code,但在尝试调试文件时遇到了一个错误。文件似乎打开了,但一旦我运行调试器,它就会显示如下: 变量${workspaceFolder}无法解析。请打开一个文件夹。
似乎找不到或复制类似的解决方案。我还尝试重新安装Visual Studio Code(这并不容易)。我至少想了解问题及其来源。
该文件是一个我正在工作的.js文件;运行一个简单的函数。它不打算与更大的工作区/程序一起运行。
在VScode中,转到文件-> 添加文件夹到工作区,然后选择程序文件所在的文件夹。
我知道这个问题已经很旧了,答案可能已经正确,但在此评论发布时的 2021年6月30日,对于我的 v1.57.1 版本的 vscode,没有一个答案适用于我。
我不得不在我的 *.code-workspace
文件中将 ${workspaceFolder}
替换为 ${workspaceFolder:my-folder-name}
。
参考资料:每个工作区文件夹范围内的变量
如果您正在使用最新的Visual Studio 1.44,请确保升级到1.44.2版本。
microsoft/vscode
issue 94725问题已得到解决。
它包含了相同的错误信息:
After some investigation the problem is the following for the workspace configuration our debug extensions appends the following attribute
__workspaceFolder:'${workspaceFolder}'
And the configuration resolver properly tries to resolve this and complains because the scope of the folder is not specified.
In a multi root workspace scope has to be specified, otherwise the resolver does not know against which folder to resolve the variables.Proposed fix: the node extension which adds this attribute should scope it if it sees that we are in a multi root folder.
So instead of${workspaceFolder}
use${FOLDER_NAME:workspaceFolder}
.
这已在提交的ae97613中得到修复。
launch.json
后遇到了错误。我只想使用 workspace.json
并在那里设置 launch
配置。我在 launch.json
中没有 zshdb
的配置条目,但在 workspace.json
中有。 - Timocode/user
文件夹下的launch.json
中,则在调试选择中会出现一个bash-deb (User)
并启动它。然后它就可以正常工作了。如果我使用相同的配置在workspace.json
中启动bash-deb(workspace)
,则会出现无法确定工作区文件夹
。所以这可能是一个新问题,因为它应该可以使用(workspace)
。 - TimoPython
和 PowerShell
中,调试可以在 (工作区)
和 (用户)
调试模式下运行。 - Timo*.code-workspace
文件中的${workspaceFolder}
替换为${FOLDER_NAME:workspaceFolder}
。(来自[这里][1])${workspaceRoot}
也可以用${FOLDER_NAME:workspaceRoot}
替换。FOLDER_NAME:
前缀修复吗?到目前为止,我的工作区没有使用它们。Version: 1.44.2
上对我有效。{
"folders": [
{
"path": "folderA"
},
{
"path": "folderB"
},
{
"path": "folderC"
}
],
"settings": {
"java.project.sourcePaths": [
"${workspaceFolder}/folderA"
]
}
}
我最近遇到了这个问题,也读了上面的答案,但作为一个初学者,我无法解决它。在我的答案中,我没有确切的做法,但我会展示对我有效的方法。