VSTS Build Definition : adding multiple feeds in Nuget restore task

As another work around, one could also choose to create a downstream feed that is only an aggregate of the upstream feeds and use the aggregate feed name in the build.

With this approach, it may be prudent to remove any non-admin users from having access to this feed to prevent packages being added to it directly.

Illustrations:





According to the docs, you have two options:

  • use NuGet.org and/or one Package Management feed in the same account/collection as the build (this is the option you chose in your example)

OR

  • to use feeds specified in a NuGet.config file you've checked into source control (if you switch the radio button to "Feeds in my nuget.config")

I just hit this with my yml pipelines and spent an hour looking at the docs. So I thought on writing an answer here since things changed so much since then.

The way to go is still to use a NuGet.config file. But that's not enough. You also need to properly configure the NuGetCommand@2 or DotNetCoreCLI@2 in order for it to use the .config file. This is the way you configure it:

  • NuGetCommand@2
- task: NuGetCommand@2
  displayName: 'Restoring NuGet packages'
  inputs:
    restoreSolution: '**/*.sln'
    feedsToUse: config
    nugetConfigPath: NuGet.Config

  • DotNetCoreCLI@2
- task: DotNetCoreCLI@2
  displayName: Restoring NuGet packages
  inputs:
    command: restore
    projects: '**/*.csproj'
    feedsToUse: config
    nugetConfigPath: NuGet.Config # Relative to root of the repository

You need specifically the feedsToUse property to have the value of config. Without it, the pipeline will not use your .config file.