从经典 CLI 迁移到 Azure Sphere CLI

如果仍在使用 Azure Sphere 经典 CLI,建议迁移到 新的 Azure Sphere CLI。 目前,可以并排安装并使用这两个版本的 CLI,但经典 CLI 不再更新或维护,并将在未来的某个日期 (在 2022) 年底之前从 SDK 中删除。 我们鼓励你熟悉这些差异,并在 2022 年底之前迁移流程和脚本,以避免中断。

若要更新到最新的 SDK,请参阅 在 Linux 上安装 Azure Sphere SDK安装适用于 Windows 的 Azure Sphere SDK

若要在 Windows 上使用 Azure Sphere CLI,请使用 PowerShell 或标准 Windows 命令提示符。 对于 Linux,请使用任何命令行界面。 有关详细信息,请参阅 运行 Azure Sphere CLI

在 Windows 上,停用的自定义 Azure Sphere 经典开发人员命令提示符 (作为开始”菜单中的快捷方式提供,) 只能与 Azure Sphere 经典 CLI 一起使用。 有关详细信息,请参阅 运行 Azure Sphere 经典 CLI

主要差异

  • 在 Azure Sphere 经典 CLI 中,可以使用多个参数来标识每个对象类型。 在 Azure Sphere CLI 中,单个参数用于标识每个对象类型。 这意味着可以使用名称或 ID 指定参数值。 这已针对 --device--tenant--product--device-group 参数实现。

    对象类型 Azure Sphere CLI Azure Sphere 经典 CLI (停用)
    装置 --device --deviceid--deviceip、 或 --devicelocation
    设备组 --device-group --devicegroupid--devicegroupname
    产品 --product --productid--productname
    租户 --tenant --tenantid
  • 经典版本中支持命令的简短形式。 在 Azure Sphere CLI 中,建议使用 Tab 补全交互式 功能查看可用命令的列表。 例如,在经典 CLI 中,可以使用 azsphere device enable-developmentazsphere dev edv 命令,而在新的 Azure Sphere CLI 中,可以使用自动完成快速键入 azsphere device enable-development 命令。

  • 某些命令允许单个参数使用多个值。 在 Azure Sphere CLI 中,可以提供单个参数,后跟以空格分隔的值列表,在 Azure Sphere 经典 CLI 中,值列表用逗号分隔。 例如:

    azsphere image-package pack-application --package-directory myDirectory --destination myImagePackage --executables filepath-1 filepath-2
    
  • 在新 CLI 中,创建租户时不会自动选择默认 租户。 必须运行 azsphere tenant select 命令来选择要用于电脑上当前用户的默认租户。 这是为了确保默认租户是正确的租户,在执行无法撤消的一次性操作时使用,就像 声明设备一样。

    使用脚本时,可以使用 参数选择默认租户 --tenant <tenant ID or tenant name>

    使用以下命令在脚本的开头设置默认租户:

    azsphere tenant select --tenant <tenant ID or tenant name>
    

    运行 命令时,还可以覆盖默认租户或指定所需的租户。 例如:

    azsphere get-support-data --destination logs.zip --tenant <tenant ID or tenant name>
    
  • 参数 --device-group 标识设备组。 设备组 ID 提供 GUID,该 GUID 可跨所有产品唯一标识设备组。 或者,可以使用 product-name>/<device-group-name 格式的<产品名称和设备组名称>对。 这对名称唯一标识特定产品的设备组。

  • 以下命令是经典 CLI 中的复合命令。 这意味着一个命令执行了多个任务。 在新 CLI 中,需要运行这两个命令。

  • 在经典 CLI 中, -o--output 参数用于指定要在其中保存文件的路径和文件名。 在新的 Azure Sphere CLI 中,使用特定于上下文的参数(例如 --destination )来指定 输入和输出路径

  • 在经典 CLI 中, -d--debug 参数在 azsphere device app start 命令中使用,以在调试模式下启动应用程序。 在新的 Azure Sphere CLI 中, --debug-mode 参数用于在调试模式下启动应用程序, --debug 并将 参数用作全局参数,以增加日志记录详细程度以显示所有调试日志。

  • 在经典 CLI 中,无法控制输出格式。 在 Azure Sphere CLI 中, -o--output 参数用于指定要 设置 CLI 输出格式的输出格式

  • 从版本 21.02 开始,从 Azure Sphere CLI 产品名称中删除了显式版本号。 此更改消除了在引用产品的不同版本时出现的混淆。

    • Azure Sphere CLI v2 及更高版本现在仅称为“Azure Sphere CLI”。
    • (CLI v1 和更低版本的 Azure Sphere CLI) 现在称为“Azure Sphere 经典 CLI”。
  • 如果使用脚本,由于上述差异,它们可能与新的 Azure Sphere CLI 不兼容。 对脚本进行所需的更新,以便在新 CLI 中正确运行。

另请参阅