开始使用 GitHub Copilot for Azure,以简化您的开发工作流并在 Azure 平台上提高您的工作效率。 本指南将指导你完成 Visual Studio 中适用于 Azure 的 GitHub Copilot 的先决条件和安装,以便可以编写第一个提示。
先决条件
若要完成本文中的步骤,请确保具备:
Azure 帐户和对 Azure 订阅的访问权限。 有关如何设置它们的详细信息,请参阅 Azure 帐户的定价页。
GitHub 帐户和 GitHub Copilot 订阅。 有关如何设置这些帐户的详细信息,请参阅 分别在 GitHub 上创建帐户和 GitHub Copilot 快速入门。
Visual Studio Code。 有关如何下载和安装它的详细信息,请参阅 “设置 Visual Studio Code”。
GitHub Copilot 扩展和 GitHub Copilot 聊天扩展。 有关如何安装这些扩展的说明,请参阅分别在 VS Code 中设置 GitHub Copilot 和 GitHub Copilot Chat 入门。
重要
GitHub Copilot 是由 GitHub 管理的单独订阅。 有关 GitHub Copilot 订阅和支持的问题,请参阅 GitHub Copilot 计划入门。
默认情况下,租户中的所有用户都可以使用 Copilot in Azure。 但是,全局管理员可以管理其组织对 Azure 中 Copilot 的访问权限。 还可以选择性地向特定 Microsoft Entra 用户或组授予访问权限。 有关详细信息,请参阅管理对 Microsoft Copilot in Azure 的访问权限。
安装 GitHub Copilot for Azure
- 在 Visual Studio Code 中,选择“ 扩展 ”图标。
- 在扩展市场中,搜索 GitHub Copilot for Azure。 出现用于 Azure 扩展的 GitHub Copilot 时,选择“ 安装”。
- 如果系统提示,请登录到 Azure 帐户。
编写第一个提示
确保已安装扩展、正确进行身份验证,并且扩展正常工作。
如果聊天窗口尚未打开,请确保在菜单栏中选择“切换聊天”按钮,或选择“切换聊天”按钮旁边的下拉列表,然后选择“打开聊天”(Ctrl+Alt+I)。
在聊天窗格底部的聊天文本区域中,输入以下提示:
Do I have any Azure resources currently running?问题的答案取决于订阅中当前在 Azure 中运行的内容。
接下来,使用以下提示:
What are your tools?完成响应显示可用于 GitHub Copilot 的 Azure 专用工具列表。 响应提供了现可供你使用的功能类型的良好概述:
I'll ask the Azure development helper to recommend custom modes relevant to listing and explaining the GitHub Copilot for Azure tools in VS Code; expected outcome: a short set of recommended modes or tips to tailor the tools explanation. Progress update: I queried the Azure development helper to get recommended custom modes for this topic. Next, I'll list and briefly explain the tools I have available (grouped and with example prompts and common uses) so you can copy/paste or use them directly in VS Code. Tools I can use (concise overview) 1. Search & navigation - Capabilities: semantic code/documentation search, file search with globs, text search (grep), list directory contents, read file contents, find usages/references. - Example prompts: - "Find all usages of MyService in this workspace." - "Search for connectionString in **/*.config files." - When to use: locating code, docs, or examples quickly inside your repo. 2. Code editing & analysis - Capabilities: insert edits into files, create or modify files, suggest refactors, report code errors, find test files. - Example prompts: - "Add a function to validate input in src/utils.js." - "Refactor this function to use async/await and update its tests." - When to use: implementing features, fixing bugs, generating or updating code. 3. Terminal & Git operations - Capabilities: run shell commands, read terminal output, show git diffs and changed files. - Example prompts: - "Run npm test and show me failing tests." - "Stage and commit the changes with message 'fix: update README'." - When to use: run builds/tests, inspect outputs, perform git workflows (if enabled). 4. Project creation & workspace setup - Capabilities: create new workspaces, scaffold projects (templates), install VS Code extensions, create notebooks. - Example prompts: - "Generate a Node.js express app scaffold in a new folder." - "Add recommended extensions for Python development." - When to use: bootstrapping projects or adding project-level config. 5. Web & API tools - Capabilities: fetch web pages, retrieve API docs (for example VS Code API references), gather remote content for research. - Example prompts: - "Fetch the Azure CLI docs for az storage account list." - "Get the VS Code extension API docs for commands." - When to use: look up official docs or examples during work. 6. Azure-specific tools - Capabilities: Azure development best practices guidance, Microsoft Learn documentation lookup, query Azure Resource Graph (when authenticated), manage Azure auth context (change tenant, sign out), generate Azure CLI / Bicep / ARM snippets, Bicep schemas, and guidance for deploying models and services. - Example prompts: - "What are Azure best practices for deploying this function app?" - "@azure /changeTenant — set my default tenant to <tenant-id>" - "Generate a Bicep template for an App Service and a Storage Account." - When to use: any task that touches Azure resources, deployment, or configuration. 7. Documentation & learning - Capabilities: search and extract Microsoft Learn articles, provide code samples from official docs, show relevant how-to steps. - Example prompts: - "Show official docs for configuring Key Vault access policies." - "Give me a short tutorial on using Azure App Configuration." - When to use: learn or reference official Microsoft guidance. How I present results - Short answers or step-by-step instructions. - Full edits (I can create or modify files if you allow the extension to act). - Commands and code snippets you can paste into your terminal. - Checks (like running tests or linters) when terminal access is allowed. Example: Quick copy-paste prompts you can use in the VS Code chat - "What are your tools?" — lists the tools (this reply). - "Find all TODO comments in this repo and open a summary." - "Generate an az CLI command to list storage accounts sorted by region." - "@azure /changeTenant" — opens tenant selection (if you need to set a default). Notes and privacy/permissions - Some capabilities (like querying your Azure resources or running commands) require you to be signed in and to enable those tools in the extension (you can enable/disable specific tools in the chat pane tool list). - I won't perform actions that need elevated permissions without verifying your explicit consent. If you'd like, I can: - Expand any tool section with more example prompts and exact commands. - Show a short step-by-step for enabling/disabling tools in the chat pane. - Generate a one-page cheatsheet you can paste into an internal docs file. Which would you like next?随着新功能和工具的添加,回复的内容可能会有所不同,并可能会随时间变化。
若要测试有关 Azure 特定工具的提示,请尝试以下提示:
What is the az command to list all my storage accounts ordered by location?完成该提示可能会生成:
I'll show the exact az CLI commands (sorted ascending/descending) plus a few useful output variants and a quick note about prerequisites. Commands - Sorted by location (ascending), full JSON: az storage account list --query "sort_by(@, &location)" -o json - Sorted by location, show only name and location in a readable table: az storage account list --query "sort_by(@, &location)[].[name,location]" -o table - Sorted by location (descending): az storage account list --query "reverse(sort_by(@, &location))" -o json - Sorted by location and include resource group and SKU in table: az storage account list --query "sort_by(@, &location)[].[name,resourceGroup,sku.name,location]" -o table Notes - Run az login first and ensure the correct subscription is selected (e.g., az account set -s "<subscription-id-or-name>"). - You need permission to list storage accounts in the chosen subscription. - The query uses JMESPath (sort_by/reverse) to order results client-side. Would you like a version that groups counts by region or that queries across all subscriptions?
在代理模式下启用和禁用工具
你可能想要禁用或重新启用 GitHub Copilot for Azure 提供的某些工具。
在聊天窗格中选择工具图标。
使用工具列表旁边的复选框来启用/禁用工具(或工具组)。
设置默认租户
如果有多个 Microsoft Entra ID 租户,则可以使用以下提示设置默认租户:
@azure /changeTenant
从顶部中心下拉列表中可用租户的列表中进行选择。
还可以在扩展设置中设置默认租户:
在 Visual Studio Code 中的活动栏上,选择“ 扩展”。 然后向下滚动到 GitHub Copilot for Azure。
选择扩展项角的齿轮图标,然后从弹出菜单中选择“设置”。
在 “设置” 选项卡上,将 Azure Resource Graph 租户设置为Microsoft Entra 租户 ID。 可以在Azure 门户中找到Microsoft Entra 租户 ID。
查看 GitHub Copilot for Azure 说明文件
说明文件(也称为“Azure Copilot 指南”)包含有关 GitHub Copilot 的高级指南,在向 GitHub Copilot 发送 Azure 工具和 Azure MCP 服务器工具的提示时添加到上下文窗口中。 此文件中的指南本质上是全局性的,这意味着,它适用于跨所有项目的 GitHub Copilot for Azure 的所有交互。 此文件位于隐藏的文件夹位置,不打算修改。 不应修改此文件,因为这样可能导致适用于 Azure 的 GitHub Copilot 性能下降或禁用,而且你的更改可能会在更新时被覆盖。
查看“Azure Copilot 指南”可以深入了解 GitHub Copilot for Azure 工具和 Azure MCP 服务器工具如何引入 GitHub Copilot,从而帮助你深入了解其工作原理。
重要
不应修改此文件。
选择
ctrl+shift+p以打开命令面板。键入
Chat: Configure Instructions并选择条目。
在下一步中,选择
AzureCopilotGuidelines。
此时会打开一个新选项卡,其中包含说明文件。
重要
不应修改此文件。
先决条件
Azure 帐户和对 Azure 订阅的访问权限。 有关如何设置它们的详细信息,请参阅 Azure 帐户的定价页。
GitHub 帐户和 GitHub Copilot 订阅。 有关如何设置这些帐户的详细信息,请参阅 分别在 GitHub 上创建帐户和 GitHub Copilot 快速入门。
Visual Studio 2022(任何版本)。 有关如何下载和安装它的详细信息,请参阅 “安装 Visual Studio”。
重要
GitHub Copilot 是由 GitHub 管理的单独订阅。 有关 GitHub Copilot 订阅和支持的问题,请参阅 GitHub Copilot 计划入门。
安装 GitHub Copilot for Azure
- 在 Visual Studio 2022 的“扩展”菜单中,选择“管理扩展”。
- 在扩展管理器中搜索并选择 GitHub Copilot for Azure (VS 2022)。 选择“ 安装 ”按钮。
- 片刻之后,你将看到一个横幅:“你的更改是计划的。 Microsoft Visual Studio 关闭时,将开始修改。关闭 Visual Studio。
- 此时会打开 VSIX 安装程序对话框,确认安装。 选择 “修改 ”按钮。
- 片刻之后,应会看到“修改完成”。 选择关闭按钮。
- 重新打开 Visual Studio 2022。
- 选择工具栏上窗口右上角的“GitHub Copilot”按钮。 选择 “打开聊天”窗口。
- 当 GitHub Copilot 聊天窗口出现时,在底部的聊天区域中,选择 代理 模式,然后选择“ 选择工具 ”按钮(两个扳手)。
- 在 “选择工具 ”对话框中,应会看到“Azure MCP 服务器”。 右侧显示“0/153”(如果未选择任何工具(当前为默认值)。 选择父节点以选择所有工具。
重要
如果在工具列表中看不到“Azure MCP 服务器”,则可能需要卸载并重新安装扩展。
编写第一个提示
如果聊天窗口尚未打开,请确保它已打开,方法是选择 “查看>GitHub Copilot 聊天” 菜单选项。 默认情况下,您应会看到聊天窗口停靠在右侧。
在聊天窗格底部的聊天文本区域中,输入以下提示:
Do I have any resources currently running?
默认情况下,GitHub Copilot 使用 ask 模式。 询问模式在聊天窗格中提供问题的答案。 代理程序模式使 GitHub Copilot 能够在工作区中执行操作。
问题的答案取决于订阅中当前在 Azure 中运行的内容。
代理模式
在代理模式下,GitHub Copilot 可以在整个 Visual Studio 工作区中执行任务、进行编辑、执行终端命令等。
GitHub Copilot for Azure 为 GitHub Copilot 提供“工具”,通过与 Azure 的深度集成来增强代理体验。
若要在“询问”和“代理模式”之间切换,请在聊天区域中的“询问”选项旁边选择向下 V 形,然后选择所需的模式。
在代理模式下启用和禁用工具
你可能想要禁用或重新启用 GitHub Copilot for Azure 提供的某些工具。
在聊天窗格中选择“选择工具”图标。
使用工具列表旁边的复选框来启用/禁用工具(或工具组)。
先决条件
Azure 帐户和对 Azure 订阅的访问权限。 有关如何设置它们的详细信息,请参阅 Azure 帐户的定价页。
GitHub 帐户和 GitHub Copilot 订阅。 有关如何设置这些帐户的详细信息,请参阅 分别在 GitHub 上创建帐户和 GitHub Copilot 快速入门。
Visual Studio 2026(任何版本)。 有关如何下载和安装它的详细信息,请参阅 “安装 Visual Studio”。
重要
GitHub Copilot 是由 GitHub 管理的单独订阅。 有关 GitHub Copilot 订阅和支持的问题,请参阅 GitHub Copilot 计划入门。
安装 GitHub Copilot for Azure
如果已安装 Visual Studio 2026,并且希望在初始安装后为 Azure 添加 GitHub Copilot,请打开 Visual Studio 安装程序并选择“ 修改 ”按钮,其中显示了可用的工作负载。
如果首次安装 Visual Studio 2026,Visual Studio 安装程序会自动显示可用的工作负载。
在“工作负荷”选项卡上,确保已选择“Azure AI 开发”。
选择“ 安装 ”按钮以完成安装。
启动 Visual Studio 2026 并创建或加载项目。
打开 GitHub Copilot 聊天。
如果系统提示,请登录到 GitHub 帐户。
如果出现系统提示,请登录到你的 Azure 帐户。
在聊天区域中,选择 “选择工具 ”按钮(两个扳手图标)以显示可用工具的列表。 通过检查 Azure 的顶级节点来启用所有 Azure 工具。
此外,选择 Azure MCP 服务器的顶部节点。
编写第一个提示
如果聊天窗口尚未打开,请确保它已打开,方法是选择 “查看>GitHub Copilot 聊天” 菜单选项。 默认情况下,您应会看到聊天窗口停靠在右侧。
在聊天窗格底部的聊天文本区域中,输入以下提示:
Do I have any resources currently running?
默认情况下,GitHub Copilot 使用 ask 模式。 询问模式在聊天窗格中提供问题的答案。 代理程序模式使 GitHub Copilot 能够在工作区中执行操作。
问题的答案取决于订阅中当前在 Azure 中运行的内容。
代理模式
在代理模式下,GitHub Copilot 可以在整个 Visual Studio 工作区中执行任务、进行编辑、执行终端命令等。
GitHub Copilot for Azure 为 GitHub Copilot 提供“工具”,通过与 Azure 的深度集成来增强代理体验。
若要在“询问”和“代理模式”之间切换,请在聊天区域中的“询问”选项旁边选择向下 V 形,然后选择所需的模式。
在代理模式下启用和禁用工具
你可能想要禁用或重新启用 GitHub Copilot for Azure 提供的某些工具。
在聊天窗格中选择“选择工具”图标。
使用工具列表旁边的复选框来启用/禁用工具(或工具组)。
相关内容
- 了解适用于 Azure 的 GitHub Copilot 及其工作原理。
- 按照快速入门了解如何在软件开发工作流中包含 GitHub Copilot for Azure。 本快速入门介绍如何将服务部署到 Azure、监视其状态以及排查问题。
- 请参阅示例提示,详细了解 Azure 并了解 Azure 帐户、订阅和资源。
- 请参阅示例提示,了解如何 为 Azure 设计和开发应用程序。
- 请参阅将应用程序部署到 Azure 的示例提示。
- 请参阅示例提示排查 Azure 资源问题。