Search code examples
azure-devopsazure-pipelinesnuget-packageazure-pipelines-yamlazure-artifacts

Selectively publish projects as Nuget packages to Azure Devops Artifacts


We have a solution with several projects. We only want 2 projects of them to be published to artifacts. Ideally we can manage this by changing settings in the project, hence the pipeline can be generic. We have been searching (trial/error) for a possible solution either on the pipeline side, either on the projects side. None of them worked or no projects ended up in the artifacts or all. Any suggestions ?

#Build and distribute nnn.Core NuGets to nnnNugets artifacts feed
name: $(Year:yyyy).$(Month).$(DayOfMonth)$(Rev:.r)

variables:
  feedName :  'nnnNugets'
  buildConfiguration: 'debug'

trigger:
- nugetify

pool:
  vmImage: windows-latest

steps:
- task: DotNetCoreCLI@2
  displayName: 'Build'
  inputs:
    command: 'build'
    projects: '**/*.csproj'
    arguments: '--configuration $(buildConfiguration)'

- task: DotNetCoreCLI@2
  displayName: 'Pack'
  inputs:
   command: pack
   versioningScheme: byBuildNumber

- task: NuGetAuthenticate@1
  displayName: 'NuGet Authenticate'

- task: NuGetCommand@2
  displayName: 'NuGet push'
  inputs:
    command: push
    publishVstsFeed: '$(feedName)'
    allowPackageConflicts: true

- task: PublishSymbols@2
  inputs:
    searchPattern: '**/bin/**/*.pdb' 
    publishSymbols: true
    symbolServerType: 'teamServices' 
    SymbolExpirationInDays: 1000 
    IndexableFileFormats: Pdb 
    

Solution

  • The solution was to update the PackagesToPack propery so that the selections matches the projects you want.include

    - task: DotNetCoreCLI@2
      displayName: 'Pack All'
      inputs:
       command: pack
       packagesToPack: '**/*.csproj; !**/Debug/**.csproj'
       versioningScheme: byBuildNumber