首页 > 解决方案 > TeamCity 还原 TFS NuGet 提要 401 未经授权

问题描述

TeamCity 专业版 2019.1.2(内部版本 66342)

NuGet.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <config>
    <add key="globalPackagesFolder" value=".\packages" />
  </config>
  <packageSources>
    <add key="TFS" value="https://tfs.mydomain.com/nuget/nuget" />
  </packageSources>
</configuration>

我有一个.NET CLI (dotnet) restore构建步骤,包括Build Feature NuGet feed credentials

从本地 shell 运行时,相应的命令可以正常工作:

>  "C:\Program Files\dotnet\dotnet.exe" restore MySolution.sln
> --packages \\packages --source https://tfs.mydomain.com/nuget/nuget --runtime win-x64 --configfile NuGet.config

但是在代理上运行的 TeamCity 作业失败401 unauthorized

[15:30:52][restore] C:\Program Files\dotnet\sdk\2.2.101\NuGet.targets(114,5): error : Failed to retrieve information about 'Dapper' from remote source 'https://tfs.mydomain.com/nuget/nuget/FindPackagesById()?id='Dapper'&semVerLevel=2.0.0'.


[15:30:52][restore] C:\Program Files\dotnet\sdk\2.2.101\NuGet.targets(114,5): error :   Response status code does not indicate success: 401 (Unauthorized).

我假设 shell dotnet restore 使用我的 Windows 登录凭据 - 正是我的构建功能 NuGet 提要凭据中指定的内容

请注意,我可以在 VisualStudio 中成功使用相同的凭据来管理 NuGet 包(在构建时恢复包)。

标签: tfsnugetteamcityrestorehttp-status-code-401

解决方案


尝试使用源 (TFS) 的密钥,而不是 url 本身。像这样;

"C:\Program Files\dotnet\dotnet.exe" restore MySolution.sln --packages \\packages --source tfs --runtime win-x64 --configfile NuGet.config

如果这不起作用,请尝试手动添加您的用户凭据

nuget sources add -name foo.bar -source C:\NuGet\local -username foo -password bar -StorePasswordInClearText -configfile %AppData%\NuGet\my.config

推荐阅读