title: Nuget restore fails on Azure Devops with message "unable to load the service index for source"
body: <p>I have a build for a .NET solution that is running in a private agent. The solution contains both .NET Core 2.1 and .NET Standard 2.0 projects. </p>
  
  <p>Some of the nuget packages installed are the following:</p>
  
  <ul>
  <li>NETStandard.Library v2.0.3</li>
  <li>Microsoft.AspNetCore.Mvc v2.0.0</li>
  <li>Microsoft.NETCore.App v2.1.5</li>
  </ul>
  
  <p>The build fails when trying to restore the nuget packages with the following error: </p>
  
  <blockquote>
    <p>"F:\Agent01\w\141\s\xxxxxxx.sln" (Restore target) (1) ->
       (Restore target) -> 
         C:\Program Files\dotnet\sdk\2.1.500\NuGet.targets(114,5): error : Unable to load the service index for source <a href="https://xxxxxxxxxx.pkgs.visualstudio.com/_packaging/xxxxxxxxxx/nuget/v3/index.json" rel="noreferrer">https://xxxxxxxxxx.pkgs.visualstudio.com/_packaging/xxxxxxxxxx/nuget/v3/index.json</a>. 
         C:\Program Files\dotnet\sdk\2.1.500\NuGet.targets(114,5): error :   Response status code does not indicate success: 401 (Unauthorized).</p>
  </blockquote>
  
  <p>Build task is the following:</p>
  
  <p><a href="https://i.stack.imgur.com/vvMjr.png" rel="noreferrer"><img src="https://i.stack.imgur.com/vvMjr.png" alt="Nuget restore build task"></a></p>
  
  <p>This is the content of <code>%appdata%\NuGet\nuget.config</code> file in the build agent:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;configuration&gt;
    &lt;packageSources&gt;
      &lt;add key="nuget.org" value="https://api.nuget.org/v3/index.json" /&gt;
      &lt;add key="MyFeed" value="https://xxxxxxxxxx.pkgs.visualstudio.com/_packaging/xxxxxxxxxx/nuget/v3/index.json" /&gt;
    &lt;/packageSources&gt;
    &lt;packageSourceCredentials&gt;
      &lt;MyFeed&gt;
        &lt;add key="Username" value="LocalBuildAgent" /&gt;
        &lt;add key="ClearTextPassword" value="xxxxxxxxxxx" /&gt;
      &lt;/MyFeed&gt;
    &lt;/packageSourceCredentials&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>I already checked a few similar questions but so far I wasn't able to find a solution for my problem. </p>
  
  <p>Some notes:</p>
  
  <ul>
  <li>Personal Access Token is NOT expired</li>
  <li>This particular build runs successfully in other build agents</li>
  <li>There is at least 1 build with a "<em>nuget restore</em>" task that was run successfully using this agent (regular <em>nuget restore</em> task, NOT .NET Core)</li>
  <li>Tried restarting the build agent, without success</li>
  <li>Tried <a href="https://stackoverflow.com/a/52694244/558486">specifying a specific version of nuget</a> before the restore, without success</li>
  <li>.NET Core SDK latest version in the build agent is 2.1.500 (multiple versions installed)</li>
  </ul>
  
  <p>What am I missing? How to fix this issue? Why can't I restore the packages using the <code>dotnet restore</code> command?</p>
  
  <h2>UPDATE:</h2>
  
  <p>Packages are restored without errors when using the <strong><em>old</em></strong> <em>Nuget Restore</em> task as follows: </p>
  
  <p><a href="https://i.stack.imgur.com/AtkHm.png" rel="noreferrer"><img src="https://i.stack.imgur.com/AtkHm.png" alt="Build definition"></a></p>
  
  <h2>UPDATE 2:</h2>
  
  <p>I am able to restore the packages using the .NET Core task v1:</p>
  
  <p><a href="https://i.stack.imgur.com/3tlGS.png" rel="noreferrer"><img src="https://i.stack.imgur.com/3tlGS.png" alt="Screenshot - restore packages using the .NET Core task v1"></a></p>
  
  <p>Or using v2 task with argument <code>--force</code>:</p>
  
  <p><a href="https://i.stack.imgur.com/InMJW.png" rel="noreferrer"><img src="https://i.stack.imgur.com/InMJW.png" alt="Screenshot - restore packages using --force"></a></p>