基本要求
要直接在 Visual Studio Code 中开发代码空间,必须登录到 GitHub Codespaces 扩展。 GitHub Codespaces 扩展需要 Visual Studio Code 2020 年 10 月 1 日版本 1.51 或更高版本。
使用 Visual Studio Marketplace 安装 GitHub Codespaces 扩展。 更多信息请参阅 Visual Studio Code 文档中的扩展 Marketplace。
- 在 Visual Studio Code 中,从左侧边栏单击 Remote Explorer 图标。
- 单击 Sign in to view GitHub...(登录以查看 Codespaces...)。
- 要授权 Visual Studio Code 访问您在 GitHub 上的帐户,请单击 Allow(允许)。
- 登录 GitHub 以审批扩展。
- 在 Visual Studio Code 中,从左侧边栏单击 Remote Explorer 图标。
- 使用“REMOTE EXPLORER(远程资源管理器)”下拉列表,然后单击 GitHub Codespaces。
- 单击 Sign in to view Codespaces...(登录以查看 Codespaces...)。
- 要授权 Visual Studio Code 访问您在 GitHub 上的帐户,请单击 Allow(允许)。
- 登录 GitHub 以审批扩展。
在 Visual Studio Code 中创建代码空间
将 GitHub 帐户连接到 GitHub Codespaces 扩展后,您可以在 Visual Studio Code 或 GitHub 上创建的代码空间中进行开发。
- 在 Visual Studio Code 中,从左侧边栏单击 Remote Explorer 图标。
- 单击 Add(添加)图标,然后单击 Create New Codespace(创建新代码空间)。
- 键入,然后单击要在其中开发仓库的名称。
- 单击要在其中开发的分支。
- Click the machine type you want to develop in.
在 Visual Studio Code 中打开代码空间
- 在 Visual Studio Code 中,从左侧边栏单击 Remote Explorer 图标。
- 在“Codespaces(代码空间)”下,单击您要在其中开发的代码空间。
- 单击 Connect to Codespace(连接到代码空间)图标。
在 Visual Studio Code 中更改机器类型
You can run your codespace on a choice of remote machine, from 2 cores to 32 cores. 每种类型都有不同的资源水平和不同的计费等级。 For information, see "About billing for Codespaces."
您可以随时更改代码空间的机器类型。
- 在 Visual Studio Code 中,打开命令调色板 (
shift command P
/shift control P
)。 - 搜索并选择“代码空间:更改机器类型”。
- 单击您要更改的代码空间。
- Choose the machine type you want to use.
如果代码空间正在运行,则会显示一条消息,询问您现在是否要重新启动并重新连接到代码空间。 如果您想立即更改用于此代码空间的机器类型,请单击 Yes(是) 。 如果您单击 No(否),或者代码空间当前未运行,更改将在代码空间下次重启时生效。
在 Visual Studio Code 中删除代码空间
- 在“Codespaces(代码空间)”下,右键点击您要删除的代码空间。
- 在下拉菜单中,单击 Delete Codespace(删除代码空间)。