How to run `dotnet list package --deprecated` for Azure Artifact feed on Azure Pipelines

1.7k views Asked by At

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?

1

There are 1 answers

2
Krzysztof Madej On BEST ANSWER

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.