1

When I try to restore packages from a private feed it seems to just ignore the feed and only look for dependencies in nuget.org.

I have a nuget authenticate that provides credentials for the feeds I wish to use.

This is how my task looks like:

- task: DotNetCoreCLI@2
  inputs:
    command: ‘custom’
    custom: ‘restore’
    projects: ‘my project.csproj’
    arguments: —-force -v:n
    feedsToUse: ‘select’
    vstsFeed: ‘myfeedurl’
    includeNuGetOrg: true

In the feeds used output it only shows the NuGet org feed and what’s strange is that this only broke recently, it was restoring fine a week ago.

Any help would be appreciated.

Things I’ve tried:

  • Adding the name of the artifact feed.
  • Nugetcommand
  • nuget config (this works but I’d like to avoid using a nuget config)
  • Adding the feed to the build agent

1 Answers1

0

I was having similar issue trying to publish a Nuget Artifact in Azure Devops and had to add the same restore task. The code below worked for me when running before the "nuget pack" task. You can hardcode parameter values to suit you but they are passed in from parent in below example.

parameters:
- name: projectName
  type: string
- name: projectFolder
  type: string
- name: configuration
  type: string
  default: release

jobs:
- job: ArtifactsPublish
  pool: #Default
    vmImage: $(linuxImageName)
  steps:
    - task: NuGetAuthenticate@0
      displayName: 'NuGet Authenticate'

    - task: DotNetCoreCLI@2
      displayName: 'Nuget Restore'
      inputs:
        command: 'restore'
        projects: '${{ parameters.projectFolder }}/*.csproj'
        feedsToUse: 'select'
        vstsFeed: '<FEED_GUID>'
        
    - task: DotNetCoreCLI@2
      displayName: 'NuGet pack'
      inputs:
        command: pack
        #nobuild: true
        versioningScheme: byPrereleaseNumber
        packagesToPack: '**/${{ parameters.projectName }}.csproj'
        #packagesToPack: '**/${{ parameters.projectName }}.nuspec'
        configuration: '${{ parameters.configuration }}'
        buildProperties: 'Description=${{ parameters.projectName }}'
        #buildProperties: 'folder=$(Pipeline.Workspace)/${{ parameters.projectName }}'
        #packDestination: '$(Pipeline.Workspace)/${{ parameters.projectName }}'
        packDirectory: '$(Build.ArtifactStagingDirectory)'
    - task: NuGetCommand@2
      displayName: 'NuGet push'
      inputs:
        command: push
        #packagesToPush: '$(Pipeline.Workspace)/${{ parameters.projectName }}/**/*.nupkg;!$(Pipeline.Workspace)/${{ parameters.projectName }}/**/*.symbols.nupkg'
        packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg'
        publishVstsFeed: '<FEED_GUID>'

This may not be the best solution but also something you can try if you are using Azure Pipelines is to click on the "Settings" hyperlink on the Edit UI and it should allow you to select a feed from your project granted correct permissions are in place.

<FEED_GUID> is a placeholder for the GUID of our private Nuget feed.

Using Azure DevOps UI: Azure DevOps UI

I hope this helps. Good luck!

Supernatix
  • 465
  • 2
  • 4
  • 14
  • Also, just on the UI example. Be mindful of cursor position, when you click settings it highlights the whole task and clicking add will overwrite selection with new code correctly but if you move cursor or deselect before that it will just add new code from that position and you will need to undo and try again. – Supernatix Sep 06 '22 at 22:43