You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何引用Azure DevOps Artifacts通用包中的自定义Flutter包

问题解决:无法从Azure DevOps Universal Package引用Dart/Flutter包

问题分析

你将包A发布到了Azure DevOps的Universal Package中,但Dart Pub的hosted依赖配置仅适用于符合Pub仓库规范的托管源。Azure DevOps Universal Package并非标准Pub仓库,因此直接用当前pubspec.yaml的配置无法识别包。

可行解决方案

方案1:将包发布到Azure DevOps Pub专用仓库

Azure Artifacts支持创建Pub类型的仓库,这是最适配Dart/Flutter的方式:

  1. 在Azure DevOps Artifacts中创建一个Pub仓库(而非Universal Package)
  2. 配置Pub使用该仓库作为源:
    dart pub token add https://feeds.dev.azure.com/{organization}/{projectname}/_apis/packaging/Feeds/{pub-feedname}/pub --env-var MY_SECRET_TOKEN
    
  3. 将包A发布到这个Pub仓库:
    dart pub publish --server=https://feeds.dev.azure.com/{organization}/{projectname}/_apis/packaging/Feeds/{pub-feedname}/pub
    
  4. 在pubspec.yaml中正确引用:
    dev_dependencies:
      A:
        hosted:
          url: https://feeds.dev.azure.com/{organization}/{projectname}/_apis/packaging/Feeds/{pub-feedname}/pub
        version: ^1.0.0
    

方案2:通过Git依赖直接引用

如果包A存储在Git仓库中(Azure DevOps Git或其他Git服务),可以跳过Universal Package,直接用Git依赖:

dev_dependencies:
  A:
    git:
      url: https://dev.azure.com/{organization}/{projectname}/_git/{repo-name}
      ref: v1.0.0
      path: path/to/packageA # 如果包在仓库子目录中

同时确保PAT拥有该Git仓库的读取权限,可通过环境变量或git config配置凭证。

方案3:本地缓存后引用(临时方案)

如果必须使用Universal Package,可以先将包下载到本地,再通过路径依赖引用:

  1. 用你提到的命令下载包到本地目录:
    az artifacts universal download --organization https://dev.azure.com/{organization}/ --project="{projectname}" --scope project --feed {feedname} --name A --version 1.0.0 --path ./local-packages/A
    
  2. 在pubspec.yaml中引用本地路径:
    dev_dependencies:
      A:
        path: ./local-packages/A
    

关键说明

  • Universal Package是通用二进制/任意文件存储,不支持Pub的包索引和版本查询逻辑,所以无法直接作为Pub的hosted源。
  • 优先使用方案1(Pub专用仓库),这是官方推荐的Dart包托管方式,能完美适配dart pub get等命令。

内容的提问来源于stack exchange,提问作者Komal Khatri

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 20:00:15