Richiban
Richiban

Reputation: 5930

AzureDevops & dotnet pack: ##[error]No files matched the search pattern

I have a project that I would like to turn into a NuGet package in an Azure DevOps CI build. The relevant files in the solution look like this:

/
    RandExp.sln
        /RandExp
            RandExp.fsproj

        /Tests
            Tests.fsproj

I have an azure-pipelines.yml file like so:

trigger:
- ci

pool:
  vmImage: "ubuntu-latest"

variables:
  buildConfiguration: "Release"

steps:
- task: GitVersion@5
  inputs:
    runtime: 'core'
    updateAssemblyInfo: true

- task: DotNetCoreCLI@2
  displayName: "DotNet restore"
  inputs:
    command: 'restore'
- task: DotNetCoreCLI@2
  displayName: "DotNet build $(buildConfiguration)"
  inputs:
    command: 'build'
    arguments: '--configuration $(buildConfiguration) --no-restore'
  
- task: DotNetCoreCLI@2
  displayName: "DotNet test ($(buildConfiguration))"
  inputs:
    command: test
    arguments: '--configuration $(buildConfiguration)'
    
- task: DotNetCoreCLI@2
  displayName: "DotNet pack"
  inputs:
    command: 'pack'
    nobuild: true
    versioningScheme: 'byBuildNumber'

- task: DotNetCoreCLI@2
  displayName: "DotNet push"
  inputs:
    command: 'push'
    packagesToPush: '$(Build.ArtifactStagingDirectory)/*.nupkg'
    nuGetFeedType: 'external'
    publishFeedCredentials: 'Public Nuget'

Everything runs fine up until the penultimate task: DotNet pack. It errors with [error]No files matched the search pattern:

Starting: DotNet pack
==============================================================================
Task         : .NET Core
Description  : Build, test, package, or publish a dotnet application, or run a custom dotnet command
Version      : 2.175.0
Author       : Microsoft Corporation
Help         : https://learn.microsoft.com/azure/devops/pipelines/tasks/build/dotnet-core-cli
==============================================================================
##[error]No files matched the search pattern.
Info: Azure Pipelines hosted agents have been updated to contain .Net Core 3.x (3.1) SDK/Runtime along with 2.1. Unless you have locked down a SDK version for your project(s), 3.x SDK might be picked up which might have breaking behavior as compared to previous versions. 
Some commonly encountered changes are: 
If you're using `Publish` command with -o or --Output argument, you will see that the output folder is now being created at root directory rather than Project File's directory. To learn about more such changes and troubleshoot, refer here: https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/build/dotnet-core-cli?view=azure-devops#troubleshooting
Finishing: DotNet pack

I've been banging my head against the wall with this one for hours; I've tried everything I can think of but cannot get anything out of this task except the same error and have now given up.

It's worth mentioning that on my machine I can cd into the root of my solution and run dotnet pack and it works, generating exactly the nupkg I expect it to.

Upvotes: 4

Views: 5444

Answers (2)

Search4Sound
Search4Sound

Reputation: 186

I had essentially the same issue in Devops (w/Azure Pipelines agent pool) when attempting a nuget push. The suggested path for packagesToPush:

'$(Build.ArtifactStagingDirectory)/*.nupkg'

would not work, nor would the equivalent to the accepted answer above (or any combination with artifact staging directory and

/**/*.nupkg 

wildcards, with and without single quotes).

I clicked the elipsis and navigated to my nuget file and changed the filename to a wildcard and now it looks like this:

$(System.DefaultWorkingDirectory)/MyPipelineName/drop/*.nupkg

This fixed the issue. I was getting, "[warning]No packages matched the search pattern", but that went away when I changed to use the path with default working directory).

Upvotes: 1

Yehor Androsov
Yehor Androsov

Reputation: 6152

According to the docs, you are missing required parameter for this task

#packagesToPack: '**/*.csproj' # Required when command == Pack

Upvotes: 4

Related Questions