1
votes

Today, I was trying to fix the build pipeline from multiple sources on NuGet restore stage and had trouble finding the right settings to use.

I have packages in three different sources,

  1. Public Nuget
  2. Private Azure DevOps artifacts.
1

1 Answers

6
votes

If you have one private repo to add to your NuGet restore then its easy,

Your YAML should look something like this

enter image description here

To add the second task, keep the mouse focus on the next line to - task: NuGetToolInstaller@1 and on the right-hand pane search for NuGet and choose the Articat you want to add

enter image description here

If you have more than one private source to restore, the best way is to restore the packages from nuget.config file.

first, add a nuget.config file on the root directory of the source control.

Add your nuget package sources as below

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
    <add key="AAA" value="https://pkgs.dev.azure.com/XXX/Prototypes/_packaging/YYY/nuget/v3/index.json" />
    <add key="BBB" value="https://pkgs.dev.azure.com/XX/IdentityServer/_packaging/YYY/nuget/v3/index.json" />
  </packageSources>
</configuration> 

and now on your YAML add the below code.

steps:
- task: NuGetToolInstaller@1

- task: NuGetCommand@2
  displayName: 'NuGet restore'
  inputs:
    restoreSolution: '**\*.sln'
    feedsToUse: config
    nugetConfigPath: 'nuget.config'

Your build pipeline should start working. Comment if there are any errors.