生产环境项目问题记录系列(二):Docker打包镜像Nuget包因权限问题还原失败

docker打包镜像遇到一个因为nuget权限验证问题导致镜像打包失败的问题,公司Nuget包用的是tfs管理的,tfs有权限验证,结果导致nuget还原失败,原有的NuGet.config文件如下:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <solution>
    <add key="disableSourceControlIntegration" value="true" />
  </solution>
  <packageRestore>
    <add key="enabled" value="True" />
    <add key="automatic" value="True" />
  </packageRestore>
  <bindingRedirects>
    <add key="skip" value="False" />
  </bindingRedirects>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
    <add key="CompanyNuGet" value="*****" />
  </packageSources>
</configuration>

使用这个nuget配置在docker中还原遇到的第一个报错如下: ”Unable to load the service index for source ...”,OK很明显是说无法访问nuget地址,突然想到可能是权限问题,所以修改配置如下:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <solution>
    <add key="disableSourceControlIntegration" value="true" />
  </solution>
  <packageRestore>
    <add key="enabled" value="True" />
    <add key="automatic" value="True" />
  </packageRestore>
  <bindingRedirects>
    <add key="skip" value="False" />
  </bindingRedirects>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
    <add key="CompanyNuGet" value="..." />
  </packageSources>
  <packageSourceCredentials>
    <CompanyNuGet>
      <add key="Username" value="NugetReader" />
      <add key="ClearTextPassword" value="i'm a secret!" />
    </CompanyNuGet>
  </packageSourceCredentials>
</configuration>

然后又报了第二个错:"/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中配置,还要再加一个重要的配置,表示使用基础验证:

<add key="ValidAuthenticationTypes" value="basic" />

最终的NuGet配置如下:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <solution>
    <add key="disableSourceControlIntegration" value="true" />
  </solution>
  <packageRestore>
    <add key="enabled" value="True" />
    <add key="automatic" value="True" />
  </packageRestore>
  <bindingRedirects>
    <add key="skip" value="False" />
  </bindingRedirects>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
    <add key="private-nuget" value="nuget url" />
  </packageSources>
  <packageSourceCredentials>
    <private-nuget>
      <add key="Username" value="NugetReader" />
      <add key="ClearTextPassword" value="Token" />
      <add key="ValidAuthenticationTypes" value="basic" />
    </private-nuget>
  </packageSourceCredentials>
</configuration>

然后镜像打包成功!


原文地址:https://www.cnblogs.com/weiBlog/p/11224055.html