0

I'm trying to run dotnet list package --deprecated for projects which used packages from Azure Artifact feed.

I wrapped it in DotNetCoreCLI task:

  - task: DotNetCoreCLI@2
    displayName: 'List deprecated packages'
    continueOnError: true
    inputs:
      command: custom
      custom: list
      arguments: 'package --deprecated'

I have sources configured in nuget.config file and this works well when I use dotnet restore. However, when I run list package I have:

The following sources were used:
   https://api.nuget.org/v3/index.json
   https://pkgs.dev.azure.com/...../nuget/v3/index.json
   https://pkgs.dev.azure.com/......./nuget/v3/index.json

and then:

error: Response status code does not indicate success: 401 (Unauthorized).

I tried to add explicitly sources in following way:

  - script: |
      nuget sources add -name "Source1" -source https://pkgs.dev.azure.com/...../nuget/v3/index.json -username anything -password %SYSTEM_ACCESSTOKEN%
      nuget sources add -name "Source2" -source https://pkgs.dev.azure.com/...../nuget/v3/index.json -username anything -password %SYSTEM_ACCESSTOKEN%
    enabled: false
    env:
      SYSTEM_ACCESSTOKEN: $(System.AccessToken)
    displayName: Add NuGet source

But this failed because:

The source specified has already been added to the list of available package sources. Provide a unique source.
The source specified has already been added to the list of available package sources. Provide a unique source.

I also modified permission to Allow project-scoped builds:

enter image description here

I also found this topic on GitHub dotnet list package --outdated` doesn't work with sources that need auth #7605 however, I don't see much help there despite this is closed now.

When I run this locally with --interactive flag I'm being constantly prompted for signing in:

enter image description here

However, dotnet restore works. I tried everything what came to my mind and still without any progress. It doesn't work both locally and on Azure Pipelines.

Have you an idea what I'm doing wrong?

Krzysztof Madej
  • 32,704
  • 10
  • 78
  • 107
  • 1
    `nuget list`/`dotnet list package` are a bit weird, last I checked using infrastructure from the nuget 2.x days which is different from that used by most of the rest of the tool. Judging by the other comments in that GitHub issue, the problem may not have been completely fixed. It's also possible that the DotNetCoreCLI task isn't setting up the authentication for custom commands. Try adding the NuGetAuthenticate task followed by a script task (e.g. PowerShell) to run `dotnet`. – Jonathan Myers Oct 22 '20 at 15:19
  • @JonathanMyers you are right. Task `- task: NuGetAuthenticate@0` before running `dotnet list package` does the job. Please, can you write as reply so I would accept it. – Krzysztof Madej Oct 23 '20 at 07:55

1 Answers1

1

I found a workaround. When I delete nuget.config and the add sources explicitly it succeeded.

- script: |
      del nuget.config
      nuget sources add -name "Source1" -source https://pkgs.dev.azure.com/...../nuget/v3/index.json -username anything -password %SYSTEM_ACCESSTOKEN%
      nuget sources add -name "Source2" -source https://pkgs.dev.azure.com/....../nuget/v3/index.json -username anything -password %SYSTEM_ACCESSTOKEN%
    enabled: true
    env:
      SYSTEM_ACCESSTOKEN: $(System.AccessToken)
    displayName: Add NuGet source

However, I wonder if there is another way, because this feels to be strange for me.

As Jonathan Myers suggested I used - task: NuGetAuthenticate@0 and it almost works. Almost because on the analyzing first project I got:

error: Problem starting the plugin 'C:\Users\VssAdministrator\.nuget\plugins\netcore\CredentialProvider.Microsoft\CredentialProvider.Microsoft.dll'. Plugin 'CredentialProvider.Microsoft' failed within 5.068 seconds with exit code -1.
error: Response status code does not indicate success: 401 (Unauthorized).

I found this topic on Developer Community and read through, but I'm still trying to solve this issue.

Krzysztof Madej
  • 32,704
  • 10
  • 78
  • 107
  • 1
    For someone that is facing the same issue, I've got the same mentioned error trying to follow the `NuGetAuthenticate@0` approach. It was solved by changing my previous step that installs the NuGet Client from version `5.4.0` to `5.5.1`. It seems to be a `credential provider` problem not with the sources. For reference: https://github.com/microsoft/artifacts-credprovider/issues/91 – Diego Rafael Souza Mar 17 '21 at 23:52
  • 1
    I have tried your Solution today and i would like to update you on the Access-Token: Working with a Windows Image, using the Access Token via `%ACCESS_TOKEN%` did not work, but i could just use the `$(System.AccessToken)` and it did the trick! – Berger Jan 25 '22 at 07:54