docker打包镜像遇到一个因为nuget权限验证问题导致镜像打包失败的问题,公司Nuget包用的是tfs管理的,tfs有权限验证,结果导致nuget还原失败,原有的NuGet.config文件如下:
"1.0" encoding="utf-8"?>"disableSourceControlIntegration" value="true" /> "enabled" value="True" /> "automatic" value="True" /> "skip" value="False" /> "nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" /> "CompanyNuGet" value="*****" />
使用这个nuget配置在docker中还原遇到的第一个报错如下: ”Unable to load the service index for source ...”,OK很明显是说无法访问nuget地址,突然想到可能是权限问题,所以修改配置如下:
"1.0" encoding="utf-8"?>"disableSourceControlIntegration" value="true" /> "enabled" value="True" /> "automatic" value="True" /> "skip" value="False" /> "nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" /> "CompanyNuGet" value="..." /> "Username" value="NugetReader" /> "ClearTextPassword" value="i'm a secret!" />
然后又报了第二个错:"/home/pi/dotnet/sdk/2.2.300/NuGet.targets(121,5): error : GSSAPI operation failed with error - An invalid status code was supplied (SPNEGO cannot find mechanisms to negotiate)."
看样子好像是验证失败,无奈网上找办法,找了半天找到了解决方案,首先我们需要在tfs中创建一个私人的Token来当做密码:
然后将创建的Token当做密码在NuGet中配置,还要再加一个重要的配置,表示使用基础验证:
"ValidAuthenticationTypes" value="basic" />
最终的NuGet配置如下:
"1.0" encoding="utf-8"?>"disableSourceControlIntegration" value="true" /> "enabled" value="True" /> "automatic" value="True" /> "skip" value="False" /> "nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" /> "private-nuget" value="nuget url" /> <private-nuget> "Username" value="NugetReader" /> "ClearTextPassword" value="Token" /> "ValidAuthenticationTypes" value="basic" /> private-nuget>
然后镜像打包成功!