预配云资源

重要

对于 Teams 代理和应用开发已弃用 Microsoft 365 代理工具包,对于所有方案,TeamsFx SDK 已完全弃用。

对于所有新的 Teams 代理和应用开发,请使用 Teams SDK 和 Teams 开发人员 CLI。

TeamsFx 与 Azure 和 Microsoft 365 云集成,使你可以通过单个命令将应用放置在 Azure 中。 TeamsFx 与 Azure 资源管理器 (ARM) 集成,使你能够预配应用程序所需的 Azure 资源,以便编写代码。

在 Visual Studio Code 中使用 Microsoft 365 代理工具包进行预配

可以在 Agents Toolkit (以前称为 Teams Toolkit) 或 Microsoft 365 Agents Toolkit CLI (以前称为 TeamsFx CLI) 中触发预配命令,为应用程序创建或更新资源。 预配命令的步骤在文件的 m365agents.yml 属性下 provision 定义。 可以查看该文件以了解创建了哪些资源。

注意

Azure 服务会在订阅中产生成本。 有关成本估算的详细信息,请参阅 定价计算器。

预配操作

下表显示了为预配而设计的操作。

teamsApp/create

定义

如果存储 Teams 应用 ID 的环境变量为空,或从 Teams 开发人员门户中找不到应用 ID,则此操作将创建新的 Teams 应用。

它运行什么资源

Teams 开发人员门户中的 Teams 应用。

如何使用它

  - uses: teamsApp/create
    with:
      # #required. Name of Teams app
      name: <your-preferred-app-name>
    # Write the information of created resources into environment file for the specified environment variable(s).
    writeToEnvironmentFile:
      # The id for Teams app
      teamsAppId: <your-preferred-env-var-name>

teamsApp/update

定义

将应用清单 (以前称为 Teams 应用清单) 应用到 Teams 开发人员门户中的现有 Teams 应用。 它使用文件中的 manifest.json 应用 ID 来确定要更新的 Teams 应用。

它运行什么资源

Teams 开发人员门户中的 Teams 应用。

如何使用它

- uses: teamsApp/update
    with:
      # Required. Relative path to the yaml file. This is the path for built zip file.
      appPackagePath: <path-to-teams-app-package-file>

teamsApp/validateManifest

定义

此操作使用环境变量呈现应用程序清单模板,并使用其架构验证应用程序清单文件。

它运行什么资源

不适用

如何使用它

  - uses: teamsApp/validate
    with:
      # Required. Relative path to the yaml file. Path to app manifest file
      manifestPath: <path-to-manifest-file>

teamsApp/validateAppPackage

定义

此操作使用有效性规则验证 Teams 应用包。

它运行什么资源

不适用

如何使用它

  - uses: teamsApp/validateAppPackage
    with:
      # Required. Relative path to the yaml file. This is the path for built zip file.
      appPackagePath: <path-to-teams-app-package-file>

teamsApp/zipAppPackage

定义

此操作会使用环境变量呈现应用清单模板,并将包含两个图标的应用清单文件压缩为 zip 文件。

它运行什么资源

不适用

如何使用它

- uses: teamsApp/zipAppPackage
    with:
      # Required. Relative path to the yaml file. This is the path for app manifest file. Environment variables in manifest will be replaced before apply to Microsoft Entra app.
      manifestPath: <path-to-manifest-file>
      # Required. Relative path to the yaml file. This is the path for built zip file.
      outputZipPath: <path-to-generated-zip-file>
      # Required. Relative path to the yaml file. This is the path for built manifest json file.
      outputJsonPath: <path-to-generated-json-file>

teamsApp/publishAppPackage

定义

此操作会将生成的 Teams 应用 zip 文件发布到租户应用目录。

它运行什么资源

租户应用目录中的 Microsoft 365 Teams 应用。

如何使用它

- uses: teamsApp/publishAppPackage
    with:
      # Required. Relative path to this file. This is the path for built zip file.
      appPackagePath: <path-to-teams-app-package>
    # Write the information of created resources into environment file for the specified environment variable(s).
    writeToEnvironmentFile:
      # The Teams app id in tenant app catalog.
      publishedAppId: <your-preferred-env-var-name>

aadApp/create

定义

如果存储 clientId 的环境变量为空,则此操作将创建新的 Microsoft Entra 应用程序来对用户进行身份验证。

它运行什么资源

Microsoft 365 租户中的 Microsoft Entra ID。

如何使用它

- uses: aadApp/create
    with:
      # Required. The Microsoft Entra app's display name. When you run aadApp/update, the Microsoft Entra app name will be updated based on the definition in manifest. If you don't want to change the name, make sure the name in Microsoft Entra app manifest is the same with the name defined here.
      name: <your-application-name>
      # Required. If the value is false, the action will not generate client secret for you
      generateClientSecret: true
      # Required. Specifies what Microsoft accounts are supported for the current application. Supported values are: `AzureADMyOrg`, `AzureADMultipleOrgs`, `AzureADandPersonalMicrosoftAccount`, `PersonalMicrosoftAccount`.
      signInAudience: "AzureADMyOrg"
    # Write the information of created resources into environment file for the specified environment variable(s).
    writeToEnvironmentFile:
      # Required. The client (application) ID of Microsoft Entra application. The action will refer the environment variable defined here to determine whether to create a new Microsoft Entra app.
      clientId: <your-preferred-env-var-name>
      # Required when `generateClientSecret` is `true`. The action will refer the environment variable defined here to determine whether to create a new client secret. It's recommended to add `SECRET_` prefix to the environment variable name so it will be stored to the .env.{envName}.user environment file.
      clientSecret: <your-preferred-env-var-name>
      # Required. The object ID of Microsoft Entra application
      objectId: <your-preferred-env-var-name>
      # Optional. The tenant ID of Microsoft Entra tenant
      tenantId: <your-preferred-env-var-name>
      # Optional. The Microsoft Entra authority
      authority: <your-preferred-env-var-name>
      # Optional. The host name of Microsoft Entra authority
      authorityHost: <your-preferred-env-var-name>

aadApp/update

定义

此操作会基于给定的 Microsoft Entra 应用清单更新 Microsoft Entra 应用程序。 它引用 Microsoft Entra 应用清单中的 ID 属性,以确定要更新的 Microsoft Entra 应用。

它运行什么资源

Microsoft 365 租户中的 Microsoft Entra ID。

如何使用它

- uses: aadApp/update
    with:
      # Required. Relative path to the yaml file. Path to the Microsoft Entra app manifest. Environment variables in manifest will be replaced before apply to Microsoft Entra app.
      manifestPath: <path-to-manifest-file>
      # Required. Relative path to the yaml folder. This action will output the final Microsoft Entra app manifest used to update Microsoft Entra app to this path.
      outputFilePath : <path-to-output-file>

botAadApp/create

定义

此操作为机器人新建或重用现有 Microsoft Entra 应用程序。

它运行什么资源

Microsoft 365 租户中的 Microsoft Entra ID。

如何使用它

- uses: botAadApp/create
    with:
      # Required. The Microsoft Entra app's display name
      name: <your-app-name>
    writeToEnvironmentFile:
      # The Microsoft Entra app's client id created for bot.
      botId: <your-preferred-env-var-name>
      # The Microsoft Entra app's client secret created for bot. 
      botPassword: <your-preferred-env-var-name>

arm/deploy

定义

此操作可并行部署给定的 ARM 模板。

它运行什么资源

Azure 订阅中。

如何使用它

- uses: arm/deploy
    with:
      # Required. You can use built-in environment variable `AZURE_SUBSCRIPTION_ID` here. TeamsFx will ask you select one subscription if its value is empty. You're free to reference other environment variable here, but TeamsFx will not ask you to select subscription if it's empty in this case.
      subscriptionId: ${{AZURE_SUBSCRIPTION_ID}}
      # Required. You can use built-in environment variable `AZURE_RESOURCE_GROUP_NAME` here. TeamsFx will ask you to select or create one resource group if its value is empty. You're free to reference other environment variable here, but TeamsFx will not ask you to select or create resource group if it's empty in this case.
      resourceGroupName: ${{AZURE_RESOURCE_GROUP_NAME}}
      # Required. The ARM templates to be deployed.
      templates:
        # Required. Relative path to the yaml file.
      - path: <path-to-arm-template>
        # Optional. Relative path to the yaml file. TeamsFx will replace the environment variable reference with real value before deploy ARM template.
        parameters: <path-to-arm-template-parameter>
        # Required. Name of the ARM template deployment.
        deploymentName: <arm-deployment-name>
      # Optional. Agents Toolkit will download this bicep CLI version from github for you, will use bicep CLI in PATH if you remove this config.
      bicepCliVersion: v0.9.1

azureStorage/enableStaticWebsite

定义

此操作可在 Azure 存储中启用静态网站设置。

它运行什么资源

Azure 存储。

如何使用它

- uses: azureStorage/enableStaticWebsite
    with:
      # Required. The resource id of Azure Storage
      storageResourceId: ${{<env-name-of-azure-storage-resource-id>}}
      # Required. The path to index page.
      indexPage: <path-to-index-page>
      # Required. The path to error page.
      errorPage: <path-to-error-page>

azureStaticWebApps/getDeploymentToken

定义

此操作从 Azure 静态 Web 应用检索部署令牌。

版本信息

v1.4

它运行什么资源

Azure Static Web Apps.

如何使用它

- uses: azureStaticWebApps/getDeploymentToken
    with:
      resourceId: ${{AZURE_STATIC_WEB_APPS_RESOURCE_ID}}
    writeToEnvironmentFile:
      deploymentToken: SECRET_TAB_SWA_DEPLOYMENT_TOKEN

script

定义

此操作执行用户定义的脚本。

它运行什么资源

不适用

如何使用它

- uses: script
    with:
     # Required. Command to run or path to the script. Succeeds if exit code is 0. '::set-teamsfx-env key=value' is a special command to generate output variables into .env file, in this case, "mykey=abc" will be added the output in the corresponding .env file.
     run: $my_key="abc"; echo "::set-teamsfx-env mykey=${my_key}"
     # Optional. Available values are: bash, sh, powershell(Powershell Desktop), pwsh(powershell core), cmd. If omitted, it defaults to bash on Linux/MacOS, defaults to pwsh on windows.
     shell: <shell-name>
     # Optional. Current working directory. Defaults to the directory of this file.
     workingDirectory: <working-directory>
     # Optional. Timeout in ms.
     timeout: <timeout-in-ms>
     # Optional. Redirect stdout and stderr to a file.
     redirectTo: <path-to-output-file>

自定义资源预配

预配步骤在文件的 m365agents.yml 属性下 provision 定义。 您可以向属性添加、删除或更新操作 provision ,以定义在供应期间要执行的预期操作。

在参数文件中引用环境变量

代理工具包支持引用 、应用清单、Microsoft Entra 应用清单和 Azure 参数文件中的 m365agents.yml环境变量中的值。 可以使用语法 ${{ENV_VARIABLE_NAME}} 引用环境变量。

以下示例将环境变量MY_AZURE_SUBSCRIPTION_IDsubscriptionId的值设置为:

subscriptionId: ${{MY_AZURE_SUBSCRIPTION_ID}}

自定义 ARM 模板文件

如果预定义模板不满足应用要求,可以创建自己的 ARM 模板或更新现有 ARM 模板,并提供操作路径 arm/deploy ,如以下模板所示:

- uses: arm/deploy
    with:
      subscriptionId: ${{AZURE_SUBSCRIPTION_ID}}
      resourceGroupName: ${{AZURE_RESOURCE_GROUP_NAME}}
      templates:
      - path: <path-to-your-arm-template>
        parameters: <path-to-your-parameter-file>
        deploymentName: <arm-deployment-name>
      bicepCliVersion: <bicep-cli-version>

该 arm/deploy 操作支持以 bicep 和 json 格式编写的 ARM 模板。 如果使用 json 格式,则可以省略该 bicepCliVersion 参数。 你需要具备 Azure 资源管理器的基本知识。 可以从 Azure 资源管理器文档开始使用 Azure 资源管理器。

自定义 Teams 应用

你可以通过添加环境变量来自定义机器人或 Teams 应用,以使用你创建的 Microsoft Entra 应用。 自定义 Teams 应用的方法包括:

将现有的 Microsoft Entra 应用用于 Teams 应用

可以按照步骤将环境变量添加到 .env 文件,以使用为 Teams 应用创建的 Microsoft Entra 应用。 如果还没有 Microsoft Entra 应用,或者已有应用但不知道在哪里可以找到正确的值,请参阅 如何在 TeamsFx 项目中使用现有的 Microsoft Entra 应用。

  1. 打开 m365agents.yml 并查找 aadApp/create 操作。

  2. 查找在属性中 writeToEnvironmentFile 存储 Microsoft Entra 应用信息的环境变量名称。 如果使用 Agents Toolkit 创建项目,则默认 writeToenvironmentFile 定义如下:

     writeToEnvironmentFile:
      clientId: AAD_APP_CLIENT_ID
      clientSecret: SECRET_AAD_APP_CLIENT_SECRET
      objectId: AAD_APP_OBJECT_ID
      tenantId: AAD_APP_TENANT_ID
      authority: AAD_APP_OAUTH_AUTHORITY
      authorityHost: AAD_APP_OAUTH_AUTHORITY_HOST
    
  3. 为步骤 2 中的每个环境变量添加值。

    1. 将以下环境变量及其值添加到文件中 env\.env.{env} 。

       AAD_APP_CLIENT_ID=<value of Microsoft Entra application's client id (application id)> # example: 00000000-0000-0000-0000-000000000000
       AAD_APP_OBJECT_ID=<value of Microsoft Entra application's object id> # example: 00000000-0000-0000-0000-000000000000
       AAD_APP_TENANT_ID=<value of Microsoft Entra's tenant id>> # example: 00000000-0000-0000-0000-000000000000
       AAD_APP_OAUTH_AUTHORITY=<value of Microsoft Entra's authority> # example: https://login.microsoftonline.com/<Directory (tenant) ID>
       AAD_APP_OAUTH_AUTHORITY_HOST=<host of Microsoft Entra's authority> # example: https://login.microsoftonline.com
       AAD_APP_ACCESS_AS_USER_PERMISSION_ID=<id of access_as_user permission> # example: 00000000-0000-0000-0000-000000000000
      
    2. 如果应用程序需要 Microsoft Entra 应用客户端密码,请将以下环境变量及其值添加到文件。env\.env.{env}.user

      SECRET_AAD_APP_CLIENT_SECRET=<value of Microsoft Entra application's client secret>
      

注意

  • 如果在 中使用不同的名称 writeToEnvironmentFile,请记得更新示例中的环境变量名称。
  • 如果不使用 aadApp/create 操作创建 Microsoft Entra 应用程序,则可以使用首选名称添加必要的环境变量,而无需执行上述步骤。
  • 确保不要在多个环境中共享相同的 Microsoft Entra 应用。

为机器人使用现有的 Microsoft Entra 应用

可以按照步骤将环境变量添加到 .env 文件,以使用为 Teams 应用创建的 Microsoft Entra 应用。 如果机器人还没有 Microsoft Entra 应用,或者已有应用但不知道在哪里可以找到正确的值,请参阅在 TeamsFx 项目中使用现有的 Microsoft Entra 应用。

  1. 打开 m365agents.yml 并查找 botAadApp/create 操作。

  2. 查找在属性中 writeToEnvironmentFile 存储 Microsoft Entra 应用信息的环境变量名称。 如果使用 Agents Toolkit 创建项目,则默认 writeToEnvironmentFile 定义如下:

     writeToEnvironmentFile:
       botId: BOT_ID
       botPassword: SECRET_BOT_PASSWORD
    
  3. 为步骤 2 中的每个环境变量添加值。

    1. 将以下环境变量及其值添加到文件中 env\.env.{env} 。

      BOT_ID=<value of Microsoft Entra application's client id (application id)> # example: 00000000-0000-0000-0000-000000000000    
      
    2. 将以下环境变量及其值添加到文件中 env\.env.{env}.user 。

      SECRET_BOT_PASSWORD=<value of Microsoft Entra application's client secret>
      

注意

  • 如果在 中使用不同的名称 writeToEnvironmentFile,请记得更新示例中的环境变量名称。
  • 如果不使用 botAadApp/create 操作创建 Microsoft Entra 应用程序,则可以使用首选名称添加必要的环境变量,而无需执行上述步骤。
  • 确保不要在多个环境中共享相同的 Microsoft Entra 应用。

另请参阅

将 Teams 应用部署到云