question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NuGet Restore fails when using Nuget.config with an azure artifacts feed

See original GitHub issue

Required Information

Entering this information will route you directly to the right team and expedite traction.

NuGet restore fails when nuget.config contains azure artifacts feed

The following issue that was closed, sums up the issue nicely: https://github.com/Microsoft/azure-pipelines-tasks/issues/7353

Environment

Azure Pipelines

Issue Description

As per https://github.com/Microsoft/azure-pipelines-tasks/issues/7353 Someone kindly left a workaround, which is to manually add authentication details in clear text for the azure artifacts nuget feed first, before doing a NuGet restore like so:

  - task: NuGetCommand@2
    displayName: 'Authenticate with NuGet feed'
    inputs:
      command: custom
      arguments: sources update -Name "Your_Azure_Artifacts_Feed_In_Config" -Username "this_value_could_anything" -Password "$(System.AccessToken)" -StorePasswordInClearText -ConfigFile NuGet.Config

- task: DotNetCoreCLI@2
    displayName: Restore
    inputs:
      command: restore
      projects: '$(solution)'
      selectOrConfig: config
      nugetConfigPath: $(Build.SourcesDirectory)/NuGet.config   

However even though this works, it’s not great in that the system access token is written to the nuget.config file in the clear.

I have also found that its not only NuGetRestore that is impacted by this feed authentication issue. If as part of your build, you install a tool using the dotnet sdk like so, you will also hit the same error:

  - script: dotnet tool install -g dotnet-format # with an azure artifacts feed in nuget.config this will fail with a 401

Surely there is a better way to authenticate with an azure artfiacts feed, once for the scope of the entire pipeline? and not have to add manual scripts to authenticate with the feed in each seperate job that may use a feed - storing the access token in the clear in the nuget.config?

Task logs

See linked issue. Log output ends up showing a 401 when anything tries to interact with an azure artifacts feed that is in the nuget.config.

C:\Program Files\dotnet\sdk\3.1.201\NuGet.targets(124,5): error : Unable to load the service index for source https://pkgs.dev.azure.com/foo/_packaging/bar/nuget/v3/index.json. [C:\Users\VssAdministrator\AppData\Local\Temp\3ro4ldor.3si\restore.csproj] C:\Program Files\dotnet\sdk\3.1.201\NuGet.targets(124,5): error : Response status code does not indicate success: 401 (Unauthorized). [C:\Users\VssAdministrator\AppData\Local\Temp\3ro4ldor.3si\restore.csproj] The tool package could not be restored. Tool ‘dotnet-format’ failed to install. This failure may have been caused by:

Troubleshooting

Checkout how to troubleshoot failures and collect debug logs: https://docs.microsoft.com/en-us/vsts/build-release/actions/troubleshooting

Error logs

[Insert error from the logs here for a quick overview]

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
Sklenicommented, Apr 27, 2020

When you edit your pipeline, there’s a variables button in the upper right corner. I added the variables there: image

0reactions
herenhuangcommented, Aug 24, 2020

Awesome, we’ll close this issue for now, though please do reopen if you have issues!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Restore NuGet packages in Azure Pipelines - Microsoft Learn
The NuGet restore task can fail for several reasons. The most common scenario is when you add a new project that requires a...
Read more >
Nuget Restore Task failing from DevOps Nuget feed with ...
We have a Build pipe line that runs a Nuget Restored Task using a Azure DevOps Nuget feed. It intermittently fails with.
Read more >
Nuget restore not working with artifact feed in Azure Devops
After searching for a long time, these are the steps necessary to make it work consistently: Setup permissions.
Read more >
How to restore nuget packages from an Azure DevOps Private ...
Place a NuGet.Config file inside your application and use it when creating the image. Use the Azure Artifacts Credentials Provider.
Read more >
Getting 401 When Restoring NuGet: Azure DevOps Private ...
This is about a common error that occurs in Visual Studio when you are trying to load a project that includes private NuGet...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found