Visual Studio Code 中的“工作区"是什么? [英] What is a 'workspace' in Visual Studio Code?

查看:98
本文介绍了Visual Studio Code 中的“工作区"是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不敢相信我在问这个问题,但我无法在文档中找到定义.如果不是很明显,我是 Visual Studio Code 的(非常)新手.

I can't quite believe I am asking this question, but I have not been able to find a definition in the documentation. In case it isn't painfully obvious, I am (very) new to Visual Studio Code.

例如,Visual Studio Code 谈到了在用户级别与工作区级别应用设置.

For example, Visual Studio Code talks about applying settings at the user level vs the workspace level.

一方面,

  • 它可以引用您打开的项目目录;或
  • 它可以指您在特定窗口中打开的所有内容.

上面引用的页面说

"工作区:这些设置存储在您的工作区中在 .vscode 文件夹中,并且仅在工作区打开时应用."

"Workspace: These settings are stored inside your workspace in a .vscode folder and only apply when the workspace is opened."

推荐答案

什么是工作区?

由一个或多个根文件夹以及所有 Visual Studio 组成的项目属于该项目的代码配置.这些配置包括:

What is a workspace?

A project that consists of one or more root folders, along with all of the Visual Studio Code configurations that belong to that project. These configurations include:

  • settings that should be applied when that project is open
  • recommended extensions for the project (useful when sharing the configuration files with colleagues)
  • project-specific debugging configurations

Visual Studio Code 并未在整个 UI 中一致使用该术语(我已经打开了一个 GitHub 问题 来解决这个问题).有时它指的是如上所述的工作区,有时它指的是作为与 .code-workspace 文件特别关联的项目的工作区.

Visual Studio Code does not use the term consistently across the UI (I've opened a GitHub issue to address this). Sometimes it refers to a workspace as described above, and other times it refers to a workspace as a project that is specifically associated with a .code-workspace file.

一个很好的例子是最近的文件小部件.请注意,在链接的屏幕截图中,所有项目都分组在相同的工作区"下.标题,这将表明所有东西都有一个工作区.但是带有 .code-workspace 文件的项目会被赋予一个工作区".后缀,与标题相矛盾并表明只有这些文件才是真正的工作区.

A good example being the recent files widget. Notice in the linked screenshot that all projects are grouped under the same "workspaces" heading, which would indicate that everything there is a workspace. But then projects with a .code-workspace file are given a "Workspace" suffix, contradicting the heading and indicating that only those files are actually workspaces.

带有注释的 JSON 文件存储所有上面提到的配置数据,除了所有root的位置属于工作区的文件夹.

A JSON with Comments file that stores all of the configuration data mentioned above, in addition to the location of all root folders belonging to a workspace.

仅当您要创建多根工作区时,在这种情况下,您将拥有一个 .code-workspace 文件,该文件会自动恢复所有工作区设置,以及您希望在 资源管理器.

Only if you're creating a multi-root workspace, in which case you'll have a single .code-workspace file that automatically restores all of the workspace settings, in addition to all of the root folders that you want to be displayed in the Explorer.

一切都是自动化的.

当您在 Visual Studio Code 中打开一个文件夹并开始修改与您当前正在处理的项目特别相关的编辑器时,Visual Studio Code 会自动创建一个 .vscode 文件夹和将其存储在您正在处理的项目文件夹的根目录中.此 .vscode 文件夹包含存储您所做更改的文件.

When you open a folder in Visual Studio Code and start making modifications to the editor that are specifically related to the project you're currently working on, Visual Studio Code automatically creates a .vscode folder and stores it in the root of the project folder that you're working on. This .vscode folder has files that store the changes you made.

例如,如果您更改您只想应用的 Visual Studio Code 设置对于您当前的项目,Visual Studio Code 会使用这些更新创建一个 settings.json 文件,并且该文件存储在 .vscode 文件夹中.

For example, if you change Visual Studio Code settings that you want to apply only to your current project, Visual Studio Code creates a settings.json file with those updates, and that file is stored in the .vscode folder.

如果您真的愿意,您可以创建一个 .code-workspace 文件,其中只包含一个根文件夹.然后您就可以直接打开项目文件夹,或者打开工作区文件.但我想不出任何理由为什么这会有好处.

You can create a .code-workspace file that includes just a single root folder if you really want to. You'd then be able to either open the project folder directly, or open the workspace file. But I can't think of any reason why this would be beneficial.

转到菜单文件将工作区另存为...

转到菜单文件将文件夹添加到工作区....

转到菜单文件打开工作区....

或者,双击 .code-workspace 文件.Visual Studio Code 不会打开实际文件.相反,它将读取该文件并打开属于该工作区的文件夹.

Alternatively, double click the .code-workspace file. Visual Studio Code won't open the actual file. Instead, it will read that file and open the folders that belong to that workspace.

转到菜单 FileOpen... 并选择目标 .code-workspace 文件.

Go to menu FileOpen... and select the target .code-workspace file.

或者,打开与该文件关联的工作区.然后打开命令面板,搜索并选择工作区:打开工作区配置文件命令.

Alternatively, open the workspace associated with that file. Then open the command palette, search for, and select the Workspaces: Open Workspace Configuration File command.

这篇关于Visual Studio Code 中的“工作区"是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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