使用 Visual Studio Code 中的 Azure 帐户扩展连接到 Azure Stack HubConnect to Azure Stack Hub using Azure Account Extension in Visual Studio Code

本文逐步说明如何使用 Azure 帐户扩展连接到 Azure Stack Hub。In this article, we will walk you through how to connect to Azure Stack Hub using the Azure Account extension. 需要更新 Visual Studio Code (VS Code) 设置。You will need to update your Visual Studio Code (VS Code) settings.

VS Code 是用于生成和调试 Web 与云应用程序的轻型编辑器。VS Code is a light-weight editor for building and debug web and cloud applications. ASP.NET Core、Python、NodeJS、Go 和其他开发人员都使用 VS Code。ASP.NET Core, Python, NodeJS, Go, and other developers use VS Code. 使用 Azure 帐户扩展可以配合订阅筛选使用 Azure 单一登录,以获取更多的 Azure 扩展。With the Azure Account extension, you can use a single Azure sign-in with subscription filtering for additional Azure extensions. 借助该扩展可以在与 VS Code 集成的终端中使用 Shell。The extension makes the Shell available in the VS Code-integrated terminal. 通过该扩展,可以使用标识管理器的 Azure AD (Azure AD) 和 Active Directory 联合身份验证服务 (AD FS) 连接到 Azure Stack Hub 订阅。Using the extension, you can connect to your Azure Stack Hub subscription using both Azure AD (Azure AD) and Active Directory Federated Services (AD FS) for your identity manager. 你可以登录到 Azure Stack Hub,选择自己的订阅,并在 shell 中打开新的命令行。You can sign in to Azure Stack Hub, select your subscription, and open a new command line in a shell.

备注

可对 Active Directory 联合身份验证服务 (AD FS) 环境使用本文所述的步骤。You can use the steps in this article for an Active Directory Federated Services (AD FS) environment. 使用 AD FS 凭据和终结点。Use your AD FS credentials and endpoints.

Azure 帐户扩展的先决条件Pre-requisites for the Azure Account Extension

  1. Azure Stack Hub 环境 1904 内部版本或更高版本Azure Stack Hub environment 1904 build or later
  2. Visual Studio CodeVisual Studio Code
  3. Azure 帐户扩展Azure Account Extension
  4. Azure Stack Hub 订阅An Azure Stack Hub subscription

连接到 Azure Stack Hub 的步骤Steps to connect to Azure Stack Hub

  1. 运行 GitHub 上的“Azure Stack Hub 工具”中的“标识”脚本。 Run the Identity script from Azure Stack Hub Tools in GitHub.

    Update-AzsHomeDirectoryTenant -AdminResourceManagerEndpoint $adminResourceManagerEndpoint `
    -DirectoryTenantName $homeDirectoryTenantName -Verbose
    Register-AzsWithMyDirectoryTenant -TenantResourceManagerEndpoint $tenantARMEndpoint `
    -DirectoryTenantName $guestDirectoryTenantName
    
  2. 打开 VS Code。Open VS Code.

  3. 选择左侧一角的“扩展”。 Select Extensions on the left-side corner.

  4. 在搜索框中输入 Azure AccountIn the search box, enter Azure Account.

  5. 依次选择“Azure 帐户”、“安装”。 Select Azure Account and select Install.

    Azure Stack Hub Visual Studio Code

  6. 重启 VS Code 以加载该扩展。Restart VS Code to load the extension.

  7. 检索用于连接到 Azure Stack Hub 中的 Azure 资源管理器的元数据。Retrieve the metadata to connect to the Azure Resource Manager in your Azure Stack Hub.

    Azure 资源管理器是一种管理框架,可用于部署、管理和监视 Azure 资源。The Azure Resource Manager is a management framework that allows you to deploy, manage, and monitor Azure resources.

    • Azure Stack 开发工具包 (ASDK) 的资源管理器 URL 为:https://management.local.azurestack.external/The Resource Manager URL for the Azure Stack Development Kit (ASDK) is: https://management.local.azurestack.external/
    • 集成系统的资源管理器 URL 为 https://management.region.<fqdn>/,其中的 <fqdn> 是你的完全限定域名。The Resource Manager URL for an integrated system is: https://management.region.<fqdn>/, where <fqdn> is your fully qualified domain name.
    • 将以下文本添加到 URL,以访问元数据:<ResourceManagerUrl>/metadata/endpoints?api-version=1.0Add the following text to your URL to access the metadata: <ResourceManagerUrl>/metadata/endpoints?api-version=1.0

    例如,用于检索 Azure 资源管理器终结点元数据的 URL 可能类似于:https://management.local.azurestack.external/metadata/endpoints?api-version=1.0For example, the URL to retrieve the metadata for your Azure Resource Manager endpoint may look something like: https://management.local.azurestack.external/metadata/endpoints?api-version=1.0

    记下返回 JSON。Make a note of the return JSON. 稍后需要使用 loginEndpointaudiences 属性的值。You will need the values for the loginEndpoint and audiences property.

  8. 按下 Ctrl+Shift+P,然后选择“首选项: 打开用户设置(JSON)”。Press Ctrl+Shift+P, and select Preferences: Open User Settings (JSON).

  9. 在代码编辑器中,使用环境的值更新以下 JSON 代码片段,然后将代码片段粘贴到设置块中。In the code editor, update the following JSON snippet with the values for your environment, and then paste snippet into the settings block.

    • 值:Values:

      参数Parameter 说明Description
      tenant-ID Azure Stack Hub 租户 ID 的值。The value of your Azure Stack Hub tenant ID.
      activeDirectoryEndpointUrl 这是 loginEndpoint 属性中的 URL。This is the URL from loginEndpoint property.
      activeDirectoryResourceId 这是 audiences 属性中的 URL。This is the URL from the audiences property.
      resourceManagerEndpointUrl 这是 Azure Stack Hub 的 Azure 资源管理器的根 URL。This is the root URL for the Azure Resource Manager for Azure Stack Hub.
      validateAuthority 如果使用 Azure AD 作为标识管理器,则可以省略此参数。You can leave out this parameter if you are using Azure AD as your identity manager. 如果使用 AD FS,请添加此参数并将值设为 falseAdd the parameter with a value of false if you are using AD FS.
    • JSON 代码片段:JSON snippet:

      "azure.tenant": "tenant-ID",
      "azure.ppe": {
          "activeDirectoryEndpointUrl": "Login endpoint",
          "activeDirectoryResourceId": "This is the URL from the audiences property.",
          "resourceManagerEndpointUrl": "Aure Resource Management Endpoint",
          "validateAuthority" : false, 
      },
      "azure.cloud": "AzurePPE"
      
  10. 保存用户设置并再次按下 Ctrl+Shift+PSave the User Settings and use Ctrl+Shift+P once again. 选择“Azure:登录到 Azure 云”。Select Azure: Sign in to Azure Cloud. 新选项“AzurePPE”将显示在目标列表中。****The new option, AzurePPE, appears in the list of targets.

  11. 选择“AzurePPE”。****Select AzurePPE. 浏览器中会加载身份验证页。The authentication page loads in your browser. 登录到你的终结点。Sign in to your endpoint.

  12. 若要测试是否已成功登录到你的 Azure Stack Hub 订阅,请按 Ctrl+Shift+ P 并选择“Azure:选择订阅”,然后查看你的订阅是否可用。To test that you have successfully logged into your Azure Stack Hub subscription, use Ctrl+Shift+ P and select Azure: Select Subscription and see if the subscription you have is available.

命令Commands

Azure:登录Azure: Sign In 登录到 Azure 订阅Sign in to your Azure subscription
Azure:使用设备代码登录Azure: Sign In with Device Code 使用设备代码登录到你的 Azure 订阅。Sign in to your Azure subscription with a device code. 在“登录”命令不起作用的设置中使用设备代码。Use a device code in setups where the Sign In command doesn't work.
Azure:登录到 Azure 云Azure: Sign In to Azure Cloud 登录到某个主权云中的 Azure 订阅。Sign in to your Azure subscription in one of the sovereign clouds.
Azure:注销Azure: Sign Out 从 Azure 订阅注销Sign out of your Azure subscription.
Azure:选择订阅Azure: Select Subscriptions 选择要使用的订阅集。Pick the set of subscriptions you want to work with. 该扩展只显示筛选的订阅中的资源。The extension only shows resources within the filtered subscriptions.
Azure:创建帐户Azure: Create an Account 如果你没有 Azure 帐户,可以立即注册一个帐户,并获得 $200 的免费信用额度。If you don't have an Azure Account, you can sign up for one today and receive $200 in free credits.
Azure:在 Shell 中打开 BashAzure: Open Bash in Shell 在 Shell 中打开运行 Bash 的新终端。Open a new terminal running Bash in Shell.
Azure:在 Shell 中打开 PowerShellAzure: Open PowerShell in Shell 在 Shell 中打开运行 PowerShell 的新终端。Open a new terminal running PowerShell in Shell.
Azure:上传到 ShellAzure: Upload to Shell 将文件上传到 Shell 存储帐户。Upload a file to your Shell storage account.

后续步骤Next steps

设置 Azure Stack Hub 中的开发环境Set up a development environment in Azure Stack Hub