skip to Main Content

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

2

Answers


  1. dotnet list package –format and –json does not work in the pipeline. Just use dotnet list package command in your pipeline like below:-

    I am using asp.net app with .net 6.0 and ran the build and publish pipeline like below:-

    trigger:
      branches:
        include:
          - main
    
    jobs:
    - job: Build
      displayName: 'Build and Publish'
      pool:
        vmImage: 'ubuntu-latest'
      steps:
      - task: UseDotNet@2
        displayName: 'Install .NET Core SDK'
        inputs:
          version: '6.x'
    
      - task: DotNetCoreCLI@2
        displayName: 'Restore Dependencies'
        inputs:
          command: 'restore'
          projects: '**/*.csproj'
    
      - task: DotNetCoreCLI@2
        displayName: 'Build Project'
        inputs:
          command: 'build'
          projects: '**/*.csproj'
          arguments: '--configuration Release'
    
      - task: DotNetCoreCLI@2
        displayName: 'Publish Project'
        inputs:
          command: 'publish'
          projects: '**/*.csproj'
          publishWebProjects: true
          arguments: '--configuration Release --output $(Build.ArtifactStagingDirectory)'
          zipAfterPublish: true
    
      - script: |
          export PATH="$PATH:/usr/share/dotnet"
          dotnet list package > $(Build.ArtifactStagingDirectory)/depts.json 
        displayName: 'Run dotnet list package'
          
      - task: PublishPipelineArtifact@1
        displayName: 'Publish Artifacts'
        inputs:
          targetPath: '$(Build.ArtifactStagingDirectory)'
          artifactName: 'publishedApp'
          publishLocation: 'pipeline'
    

    OR

      - script: |
          export PATH="$PATH:/usr/share/dotnet"
          dotnet list package 
        displayName: 'Run dotnet list package'
    

    Output:-

    enter image description here

    enter image description here

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search