dparkar
dparkar

Reputation: 2134

VSTS Build Definition : adding multiple feeds in Nuget restore task

I am in the process of setting up a VSTS build definition. The build definition is simple. Steps :

  1. get the source from VSTS Git repo's master branch
  2. restore nuget packages
  3. run msbuild

Step 2 is setup as following :

enter image description here

When I use "Feed(s) I select here", it only allows me to select one feed. Is this a bug ? Or the only way to use multiple feeds is through Nuget.config ?

Upvotes: 16

Views: 13481

Answers (4)

jpgrassi
jpgrassi

Reputation: 5742

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.

Upvotes: 9

Josh Gust
Josh Gust

Reputation: 4445

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:




Upvotes: 9

Marina Liu
Marina Liu

Reputation: 38096

For now, it can only select one feed for Feed(s) I select here option in NuGet restore task.

And I created an issue Enable to select multiple feeds in NuGet restore task Feed(s) I select here for this feature, you can follow up.

The workarounds for now is using the NuGet.config file which contains the feeds you need to use. Or add the VSTS feeds you need to use as endpoints, and then select these feed from Credentials for feeds outside this account/collection option.

Upvotes: 2

Yan Sklyarenko
Yan Sklyarenko

Reputation: 32240

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")

Upvotes: 6

Related Questions