开始使用 Azure 的 GitHub Copilot

开始使用 Azure GitHub Copilot,以简化开发工作流并在 Azure 平台上提高工作效率。 本指南将引导你完成Visual Studio中Azure GitHub Copilot的先决条件和安装,以便可以编写第一个提示。

先决条件

若要完成本文中的步骤,请确保具备:

  • Azure帐户和对Azure订阅的访问权限。 有关如何设置这些帐户的详细信息,请参阅 Azure 帐户的 pricing 页面

  • GitHub帐户和GitHub Copilot订阅。 有关如何设置它们的详细信息,请参阅 在 GitHub 上创建账户GitHub Copilot 快速入门指南

  • Visual Studio Code。 有关如何下载和安装它的详细信息,请参阅 Setting up Visual Studio Code

  • GitHub Copilot扩展和GitHub Copilot聊天扩展。 有关如何安装这些扩展的说明,请参阅在 VS Code 中设置 GitHub Copilot,以及在 VS Code 中开始使用 GitHub Copilot 聊天。

重要

GitHub Copilot是由GitHub管理的单独订阅。 有关GitHub Copilot订阅和支持的问题,请参阅 从GitHub Copilot计划开始

默认情况下,Azure中的Copilot可供租户中的所有用户使用。 但是,全局管理员可以管理其组织在 Azure 中对 Copilot 的访问权限。 还可以选择向特定Microsoft Entra用户或组授予访问权限。 有关详细信息,请参阅 在 Azure 中管理对 Microsoft Copilot 的访问

为Azure安装GitHub Copilot

  1. 在Visual Studio Code中,选择 Extensions 图标。
  2. 在扩展市场板中,搜索 GitHub Copilot 用于 Azure。 当 GitHub Copilot for Azure 扩展显示时,选择 安装
  3. 如果系统提示,请登录到Azure帐户。

编写第一个提示

  1. 确保已安装扩展、正确进行身份验证,并且扩展正常工作。

  2. 如果聊天窗口尚未打开,请确保在菜单栏中选择“切换聊天”按钮,或选择“切换聊天”按钮旁边的下拉列表,然后选择“打开聊天”(Ctrl+Alt+I)。

    显示“切换聊天”菜单打开并选择“打开聊天”菜单选项的屏幕截图。

  3. 在聊天窗格底部的聊天文本区域中,输入以下提示:

    Do I have any Azure resources currently running?
    

    问题的答案取决于你在 Azure 的订阅中当前运行的内容。

  4. 接下来,使用以下提示:

    What are your tools?
    

    GitHub Copilot的完成响应显示出适用于GitHub Copilot for 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?
    
    

    随着新功能和工具的添加,回复的内容可能会有所不同,并可能会随时间变化。

  5. 若要测试有关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?
    
    

在代理模式下启用和禁用工具

你可能希望禁用或重新启用Azure GitHub Copilot提供的某些工具。

  1. 在聊天窗格中选择工具图标。

    聊天窗格的屏幕截图,其中突出显示了“配置工具”图标。

  2. 使用工具列表旁边的复选框来启用/禁用工具(或工具组)。

    Visual Studio Code 工具列表的截图。

设置默认租户

如果有多个 Microsoft Entra ID 租户,则可以使用以下提示设置默认租户:

@azure /changeTenant

从顶部中心下拉列表中选择可用租户。

还可以在扩展设置中设置默认租户:

  1. 在Visual Studio Code,在活动栏上,选择Extensions。 然后向下滚动到 GitHub Copilot Azure

  2. 选择扩展项角的齿轮图标,然后从弹出菜单中选择“设置”。

    显示 GitHub Copilot for Azure 弹出菜单的截图。

  3. Settings 选项卡上,将 Azure Resource Graph 租户设置为 Microsoft Entra 租户 ID。 可以在Azure门户中找到Microsoft Entra租户 ID。

    截图显示了“设置”选项卡,其中有一个用于设置 Azure Resource Graph 租户的选项。

查看GitHub Copilot for Azure 的说明文件

instructions 文件(也称为“Azure Copilot 准则”)包含高层次的指导,这些指导用于在向 GitHub Copilot 发送提示以使用 Azure 工具和 Azure MCP 服务器工具时,添加到上下文窗口中。 此文件中的指南本质上是全局性的,这意味着,它适用于所有项目中Azure GitHub Copilot之间的所有交互。 此文件位于隐藏的文件夹位置,不打算修改。 不应修改此文件,因为这可能会导致GitHub Copilot for Azure降级或被禁用,并且你的更改可能会被GitHub Copilot for Azure的新更新覆盖。

查看“Azure Copilot 指南”可以提供关于如何将 GitHub Copilot for Azure 工具和 Azure MCP 服务器工具引入 GitHub Copilot 的见解,帮助你更深入地理解其工作原理。

重要

不应修改此文件。

  1. 选择ctrl + shift + p以打开命令面板。

  2. 键入 Chat: Configure Instructions 并选择条目。

    Visual Studio Code 命令调色板中的输入截图。

  3. 在下一步中,选择 AzureCopilotGuidelines

    选择 Azure Copilot Guidelines 的选项截图。

  4. 此时会打开一个新选项卡,其中包含说明文件。

    GitHub Copilot 为 Azure 的说明文件的截图。

    重要

    不应修改此文件。

先决条件

若要完成本文中的步骤,请确保具备:

重要

GitHub Copilot是由GitHub管理的单独订阅。 有关GitHub Copilot订阅和支持的问题,请参阅 从GitHub Copilot计划开始

默认情况下,Azure中的Copilot可供租户中的所有用户使用。 但是,全局管理员可以管理其组织在 Azure 中对 Copilot 的访问权限。 还可以选择向特定Microsoft Entra用户或组授予访问权限。 有关详细信息,请参阅 在 Azure 中管理对 Microsoft Copilot 的访问

为Azure安装GitHub Copilot

Azure MCP 内置于 2022 Visual Studio。 无需单独安装 GitHub Copilot for Azure 扩展;Azure MCP 工具已包含在 Azure 开发工作负载中。

  1. 如果已安装 Visual Studio 2022,并且希望在初始安装后为Azure添加GitHub Copilot,请打开 Visual Studio Installer,然后选择显示可用工作负载的 Modify 按钮。

    如果首次安装 Visual Studio 2022,Visual Studio安装程序会自动显示可用的工作负载。

  2. 在“工作负荷”选项卡上,确保已选择Azure开发工作负荷。

    Screenshot 显示Visual Studio安装程序,其中突出显示了“Azure开发”按钮。

  3. 选择“ 安装 ”按钮以完成安装。

注释

Azure MCP 工具通过常规 Visual Studio 更新进行支持。 若要获取更新,请使用 Visual Studio Installer(ModifyUpdate),并确保使用的是最新的 Visual Studio 2022 版本。

  1. 启动 Visual Studio 2022 并创建或加载项目。

  2. 打开 GitHub Copilot 对话助手。

  3. 如果系统提示,请登录到GitHub帐户。

  4. 如果系统提示,请登录到Azure帐户。

  5. 在聊天区域中,选择“选择工具”按钮(两个扳手图标)以显示可用工具的列表。 通过检查顶级节点Azure MCP Server v.x.x.x来启用所有 Azure 工具。

    屏幕截图显示了选择工具对话框,其中Azure MCP 服务器节点已被选中。

注释

Azure MCP 工具在 2022 Visual Studio中默认处于禁用状态,在使用前需要手动启用。 从“选择工具”对话框启用后,Azure MCP 工具选择会跨会话保留。 Visual Studio 2026 特定工具在 Visual Studio 2022 中不可用。

编写第一个提示

  1. 如果聊天窗口尚未打开,请确保通过选择 View>GitHub Copilot 对话助手 菜单选项将其打开。 默认情况下,您应会看到聊天窗口停靠在右侧。

    显示 Visual Studio 2022 中 GitHub Copilot 对话助手 窗口的截图。

  2. 在聊天窗格底部的聊天文本区域中,输入以下提示:

    Do I have any resources currently running?
    

    显示在 Visual Studio 2022 的聊天区域中键入示例提示的截图。

默认情况下,GitHub Copilot使用 ask 模式。 询问模式在聊天窗格中提供问题的答案。 Agent模式使GitHub Copilot能够在工作区中执行操作。

问题的答案取决于你在 Azure 的订阅中当前运行的内容。

代理模式

在代理模式下,GitHub Copilot可以在整个Visual Studio工作区中执行任务、进行编辑、执行终端命令等。

Azure专用GitHub Copilot通过与Azure的深度集成,为GitHub Copilot提供了“工具”,以增强用户代理体验。

若要在“询问”和“代理模式”之间切换,请在聊天区域中的“询问”选项旁边选择向下 V 形,然后选择所需的模式。

显示 Visual Studio 2022 聊天区域中的模式菜单的屏幕截图。

在代理模式下启用和禁用工具

你可能希望禁用或重新启用Azure GitHub Copilot提供的某些工具。

  1. 在聊天窗格中选择“选择工具”图标。

    在 Visual Studio 2022 中,当单击“选择工具”按钮时,聊天窗格的截图。

  2. 使用工具列表旁边的复选框来启用/禁用工具(或工具组)。

先决条件

若要完成本文中的步骤,请确保具备:

重要

GitHub Copilot是由GitHub管理的单独订阅。 有关GitHub Copilot订阅和支持的问题,请参阅 从GitHub Copilot计划开始

默认情况下,Azure中的Copilot可供租户中的所有用户使用。 但是,全局管理员可以管理其组织在 Azure 中对 Copilot 的访问权限。 还可以选择向特定Microsoft Entra用户或组授予访问权限。 有关详细信息,请参阅 在 Azure 中管理对 Microsoft Copilot 的访问

为Azure安装GitHub Copilot

  1. 如果已安装 Visual Studio 2026,并且希望在初始安装后为Azure添加GitHub Copilot,请打开 Visual Studio Installer,然后选择显示可用工作负载的 Modify 按钮。

    如果首次安装 Visual Studio 2026,Visual Studio安装程序会自动显示可用的工作负载。

  2.  在“工作负荷”选项卡上,确保已选择“Azure AI 开发”。

    显示 Visual Studio 安装程序可用工作负载的屏幕截图,其中 Azure AI 开发选项被选择并被突出显示。

  3. 选择“ 安装 ”按钮以完成安装。

  4. 启动 Visual Studio 2026 并创建或加载项目。

  5. 打开 GitHub Copilot 对话助手。

  6. 如果系统提示,请登录到GitHub帐户。

  7. 如果系统提示,请登录到Azure帐户。

  8. 在聊天区域中,选择 “选择工具 ”按钮(两个扳手图标)以显示可用工具的列表。 通过检查Azure顶部节点来启用所有Azure工具。

    此屏幕截图显示了选择工具的对话框,其中已选中 Azure 节点。

    此外,选择 Azure MCP Server 的顶部节点。

    屏幕截图显示了选择工具对话框,其中Azure MCP 服务器节点已被选中。

编写第一个提示

  1. 如果聊天窗口尚未打开,请确保通过选择 View>GitHub Copilot 对话助手 菜单选项将其打开。 默认情况下,您应会看到聊天窗口停靠在右侧。

    截图显示 Visual Studio 2026 中的 GitHub Copilot 聊天窗口。

  2. 在聊天窗格底部的聊天文本区域中,输入以下提示:

    Do I have any resources currently running?
    

    截图显示在 Visual Studio 2026 的聊天区域中键入的示例提示。

默认情况下,GitHub Copilot使用 ask 模式。 询问模式在聊天窗格中提供问题的答案。 Agent模式使GitHub Copilot能够在工作区中执行操作。

问题的答案取决于你在 Azure 的订阅中当前运行的内容。

代理模式

在代理模式下,GitHub Copilot可以在整个Visual Studio工作区中执行任务、进行编辑、执行终端命令等。

Azure专用GitHub Copilot通过与Azure的深度集成,为GitHub Copilot提供了“工具”,以增强用户代理体验。

若要在“询问”和“代理模式”之间切换,请在聊天区域中的“询问”选项旁边选择向下 V 形,然后选择所需的模式。

显示 Visual Studio 2026 聊天区域中的模式菜单的截图。

在代理模式下启用和禁用工具

你可能希望禁用或重新启用Azure GitHub Copilot提供的某些工具。

  1. 在聊天窗格中选择“选择工具”图标。

    Visual Studio 2026 中聊天窗格的屏幕截图,其中单击了选择工具按钮。

  2. 使用工具列表旁边的复选框来启用/禁用工具(或工具组)。