TFS build .net Core with nuget restore end in error

TFS build .net Core with nuget restore end in error

尝试在 tfs 上构建 .net Code 2.2 解决方案时有一个 nuget 恢复任务。它正在尝试连接到我们的内部提要。然后它失败了。在构建日志中我们有:

error : Unable to load the service index for source http://internalSource/index.json. [D:\dummy.csproj]

error : No credentials are available in the security package [D:\dummy.csproj]

查看 TFS 生成的文件,它没有使用我们在解决方案中声明的凭据。 我们的 nuget.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageRestore>
    <!-- Allow NuGet to download missing packages -->
    <add key="enabled" value="True" />
    <add key="automatic" value="True" />
  </packageRestore>
  <packageSources>
    <clear />
    <add key="PackageSTN" value="http://internal/index.json" />
  </packageSources>
  <activePackageSource>
    <add key="All" value="(Aggregate source)" />
  </activePackageSource>
  <packageSourceCredentials>
    <PackageSTN>
        <add key="Username" value="user" />
        <add key="Password" value="pwd" />
    </PackageSTN> 
  </packageSourceCredentials>
</configuration>

构建给我们的 TFS 上的那个:

<configuration>
  <packageRestore>
    <add key="enabled" value="True"/>
    <add key="automatic" value="True"/>
  </packageRestore>
  <packageSources>
    <clear/>
  <add key="PackageSTN" value="http://internal/index.json"/></packageSources>
  <activePackageSource>
    <add key="All" value="(Aggregate source)"/>
  </activePackageSource>
    <packageSourceCredentials>       
        <PackageSTN>
            <add key="Username" value="VssSessionToken"/>
            <add key="ClearTextPassword" value="Too Big to be display"/>
        </PackageSTN>
    </packageSourceCredentials>
</configuration>

它似乎在尝试使用某些 VssSessionToken TFS 帐户登录。

此外,我们将服务器上的 %APPDATA% nuget.config 替换为带有我们凭据的那个,以防它会查看内部,也不走运。

TFS build .net Core with nuget restore end in error

我们知道,当我们select选项Feeds in my NuGet.config时,我们还需要提供Credentials for feeds outside this account/collection:

如果我们在 NuGet 连接 window 的字段 "Personal Access Token" 中使用从 CredentialProvider.VSS.exe 获得的令牌,我们可能会遇到像您一样的问题。我们从 CredentialProvider.VSS.exe 获得的令牌是一个 short-lived 令牌,您可以将其替换为 PAT(个人访问令牌)以检查它是否适合您。

查看 了解更多详情。

此外,如果您使用的是旧版 nuget.exe,您可以使用任务 NuGet Tool Installer 来更新它。

如果以上内容对您没有帮助,请分享您关于 nuget 恢复任务的构建定义以及如何在 account/collection.

之外为订阅源添加凭据的步骤

希望这对您有所帮助。

最后我们做了一个powershell脚本,by-pass这个:/

try
{
    $solutionSln = $env:BUILD_SOURCESDIRECTORY + $env:solutionSln
    $nugetConfig = $env:BUILD_SOURCESDIRECTORY + $env:nugetConfig

    Write-Host "dotnet restore $solutionSln --configfile  $nugetConfig --verbosity Detailed --no-cache"
    dotnet restore $solutionSln --configfile  $nugetConfig --verbosity Detailed --no-cache
}
catch {
    Write-Host $_
    exit 1
}