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

Azure DevOps Server私有NuGet源dotnet tool restore报401未授权

解决Azure DevOps Server 2020中dotnet tool restore 401未授权问题

1. 核对nuget.config的私有源配置

先确认你的nuget.config里的私有源URL和Azure Artifacts的源地址完全匹配,必须带上/v3/index.json后缀。示例配置:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="MyPrivateFeed" value="http://your-azure-devops-server:8080/tfs/CollectionName/_packaging/FeedName/nuget/v3/index.json" />
  </packageSources>
</configuration>

Azure DevOps Server的私有源必须用完整的v3索引路径,只写到Feed层级会导致认证失败。

2. 确保.NET Core任务能拿到认证变量

虽然NuGet authenticate任务已经设置了VSS_NUGET_ACCESSTOKEN和VSS_NUGET_URI_PREFIXES,但.NET Core任务可能存在环境隔离,导致变量没继承。解决办法:

  • 在.NET Core任务配置里勾选「继承所有环境变量」
  • 或者手动在任务的「环境变量」部分添加这两个变量,值分别引用$(System.AccessToken)和你的私有源前缀(比如http://your-azure-devops-server:8080/tfs/CollectionName/_packaging/)

3. 显式指定nuget.config路径

有时候默认加载的nuget.config不是你项目里的那个,执行命令时直接指定路径:

dotnet tool restore --configfile $(Build.SourcesDirectory)/nuget.config --verbosity detailed

替换路径为你项目中nuget.config的实际位置。

4. 检查Build Service账号的权限范围

确认Build Service账号(格式通常是[项目集合名称]\Project Collection Build Service ([组织/实例名])):

  • 不仅拥有目标Feed的Contributor权限,还要在项目级有Contributor权限
  • 直接添加到Feed权限列表里,不要依赖组继承(组权限偶尔会有生效延迟)

5. 换用命令行任务执行dotnet命令

试试用命令行任务代替.NET Core任务,手动设置环境变量后再执行命令,避免.NET Core任务的环境隔离问题:

set VSS_NUGET_ACCESSTOKEN=$(System.AccessToken)
set VSS_NUGET_URI_PREFIXES=http://your-azure-devops-server:8080/tfs/CollectionName/_packaging/
dotnet tool restore --verbosity detailed

6. 升级Azure DevOps Agent版本

Azure DevOps Server 2020建议搭配2.174.x及以上版本的Agent,旧版本对dotnet tool的凭证支持可能存在缺陷,升级Agent后再测试。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.12 16:20:28