快速入门:浏览演示扩展

在本快速入门中,你将安装 Azure 开发人员 CLI (azd) 演示扩展,并使用它来探索 azd 扩展框架功能。 扩展 提供了一种方法来添加新功能、自动化工作流,并将其他服务与 azd集成。 演示扩展提供了如何在扩展中实现各种功能的示例,例如如何提示用户输入或显示有关项目的信息。

初始化项目

若要执行前面的步骤,请初始化 hello-azd 初学者模板。 您还可以使用自己的模板同时进行操作。

azd init -t hello-azd

安装扩展

完成以下步骤以安装演示扩展:

  1. 确保在您的azd 配置中启用扩展:

    azd config set alpha.extensions on
    
  2. 从官方注册表安装演示扩展:

    azd extension install microsoft.azd.demo
    
  3. 通过列出已安装的扩展来验证扩展是否已安装。

    azd extension list --installed
    

使用演示扩展工作流

安装后,演示扩展会添加新命令,你可以使用它来浏览扩展框架功能示例。

  1. 运行该 azd demo 命令以查看可用演示命令的列表:

    azd demo
    

    输出应如下所示:

    Demonstrates AZD extension framework capabilities.
    
    Usage:
      azd [command]
    
    Available Commands:
      colors      Displays all ASCII colors with their standard and high-intensity variants.        
      context     Get the context of the AZD project & environment.
      listen      Starts the extension and listens for events.
      prompt      Examples of prompting the user for input.
      version     Prints the version of the application
    
    Flags:
          --debug   Enable debug mode
      -h, --help    help for azd
    
    Use "azd [command] --help" for more information about a command.
    
  2. azd demo version运行命令以显示应用的版本:

    azd demo version
    

    输出格式应如下所示:

    Version: 0.2.0
    Commit: 611d05a6f7190f3bda379e92b4ece6470584c6f0
    Build Date: 2025-04-23T17:21:58Z
    
  3. 运行azd demo context命令以显示azd项目和环境的上下文。

    azd demo context
    
  4. azd demo prompt运行命令以探索如何使用扩展提示用户输入的示例:

    azd demo prompt
    

    工作流的第一步演示如何筛选列表:

    ? Which Azure services do you use most with AZD?: Container Apps
    
      Filter: Type to filter list
    
      > [✔] Container Apps
        [ ] Functions
        [ ] Static Web Apps
        [ ] App Service
        [ ] Cosmos DB
        [ ] SQL Database
        ...
    

    选择 “容器应用 ”,然后按 Enter。 继续查看其他提示,了解其他提示选项的示例,例如布尔型选择 是/否 或列表项选择。