如何从Artifact Feed运行NuGet工具包?Azure DevOps Pipeline求助
解决Azure Pipelines中安装自定义NuGet工具的NU1301错误
问题原因
你遇到的NU1301错误是因为Azure Pipelines托管代理没有权限访问你的私有Artifact Feed。本地能正常访问是因为本地已存储Feed的认证凭据,但流水线环境未配置对应认证。
解决方案步骤
1. 创建NuGet服务连接
在Azure DevOps项目内操作:
- 进入项目设置 > 服务连接,点击新建服务连接
- 选择NuGet类型,填写你的Feed URL,用**个人访问令牌(PAT)**认证,PAT需具备
Packaging Read权限 - 给服务连接命名(如
MilanDjukicFeedConnection)并保存
2. 修改流水线配置
更新YAML流水线,添加认证任务并调整工具安装逻辑:
pool: vmImage: windows-latest jobs: - job: RunTool displayName: Run Tool steps: # 认证NuGet服务连接,赋予代理访问私有Feed的权限 - task: NuGetAuthenticate@1 inputs: nuGetServiceConnections: 'MilanDjukicFeedConnection' # 替换为你创建的服务连接名称 # 本地安装.NET工具(避免全局路径问题) - task: DotNetCoreCLI@2 inputs: command: 'custom' custom: 'tool' arguments: 'install MigrationApp --version 8.0.18 --tool-path .' # 运行安装完成的工具 - task: CmdLine@2 inputs: script: '.\MigrationApp.exe' # Windows环境用.exe后缀,Linux/macOS直接写./MigrationApp
关键说明
NuGetAuthenticate@1任务会自动配置已认证的源,无需在dotnet tool install命令中手动指定--add-source- 使用
--tool-path .本地安装工具,可规避全局安装带来的PATH环境变量问题 - 确保你的PAT拥有读取Feed包的足够权限
内容的提问来源于stack exchange,提问作者milandjukic88
相关产品推荐
相关产品推荐

