Search code examples
.netazurenugetdevopspipeline

.net command list package --format json in azure pipeline


I would like to run the following dotnet command on a hosted Azure pipeline to generate a nuget package list:

dotnet list package --format json --include-transitive > /home/vsts/work/1/a/depts.json

However, the command is not found:

Possible reasons are:
  * You misspelled a built-in dotnet command.
  * You wanted to run a .NET program, but dotnet-list package --format json --include-transitive > /home/vsts/work/1/a/depts.json is not present.
  * You wanted to run a global tool, but an executable prefixed with dotnet with that name could not be found in the PATH.

If I understand the documentation correctly, then I need.net core 3.1 or later versions. In the pipeline the version 2.221.0 is used. That's why I tried to install version 3.1.31. However, that doesn't work either.

Here is my pipeline:

trigger:
- master

pool:
  vmImage: ubuntu-latest

# install .net core sdk 6 for restore
steps:
- task: UseDotNet@2
  displayName: 'Use .NET Core sdk'
  inputs:
    packageType: 'sdk'
    version: '6.0.x'
    includePreviewVersions: true

# restore solution
- task: DotNetCoreCLI@2
  inputs:
    command: 'restore'
    projects: '**/*.sln'
    feedsToUse: 'config'
    nugetConfigPath: 'nuget.config'
    externalFeedCredentials: 'TelerikFeed'
  displayName: Restore nuget packages

# install .net core runtime
- task: UseDotNet@2
  displayName: 'Use .NET Core runtime'
  inputs:
    packageType: 'runtime'
    version: '3.x'
    installationPath: $(Agent.ToolsDirectory)/dotnet

# execute list package command
- task: DotNetCoreCLI@2
  inputs:
    command: 'custom'
    custom: 'list package --format json --include-transitive > $(Build.ArtifactStagingDirectory)/depts.json'

# also not working
- task: Bash@3
  inputs:
    targetType: 'inline'
    script: |
      dotnet list package --format json --include-transitive > $(Build.ArtifactStagingDirectory)/depts.json

# publish file
- task: PublishBuildArtifacts@1
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)'
    ArtifactName: 'drop'
    publishLocation: 'Container'

Can anyone tell me what I am doing wrong or if my scenario is even possible? Thanks in advance


Solution

  • The top of the docs for dotnet list package says it's available in .NET Core 3.1. However, that just refers to dotnet list package generally. If you scroll down to where --format is documented, it says:

    Available starting in .NET SDK 7.0.200.

    Hence, you need to use the .NET 7 SDK.