Sylvain Lucas
Sylvain Lucas

Reputation: 71

TFS build .net Core with nuget restore end in error

While trying to build on tfs a .net Code 2.2 solution have a nuget restore task. it's trying to connect to our internal feeds. Then it fail. In the build logs we have :

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]

Looking at TFS generated files, it's not using the credential we declare in our solution. Our 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>

The one on TFS the build give us:

<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>

Seem like it's trying to use some VssSessionToken TFS account to log on.

In addition we replace the %APPDATA% nuget.config on the server with the one with our credential, in case it will have a look inside, no luck as well.

Upvotes: 0

Views: 2014

Answers (2)

Sylvain Lucas
Sylvain Lucas

Reputation: 71

Finally we did a powershell script, to by-pass this :/

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
}

Upvotes: 1

Leo Liu
Leo Liu

Reputation: 76670

TFS build .net Core with nuget restore end in error

As we know, when we select the option Feeds in my NuGet.config, we also need provide the Credentials for feeds outside this account/collection:

enter image description here

If we use the token we got from CredentialProvider.VSS.exe in the field "Personal Access Token" in the NuGet connection window, we may got the issue like you. The token we got from CredentialProvider.VSS.exe is a short-lived token, you could replace it with PAT (Personal Access Token) to check if it work for you.

Check this thread for some more details.

Besides, if you are using the old nuget.exe, you can use the task NuGet Tool Installer to update it.

If above not help you, please share your build definition about nuget restore task and the steps how to add the Credentials for feeds outside this account/collection.

Hope this helps.

Upvotes: 1

Related Questions