Azure devops and custom NuGet feeds

Azure devops and custom NuGet feeds

If your setting up a CI pipleline on Azure Devops for a site which uses a NuGet feed from a source that isn't on nuget.org you may see the error:

"The nuget command failed with exit code(1) and error(Errors in packages.config projects Unable to find version..."

On your local dev machine you will have added extra an extra NuGet feed source through visual studio which will update a global file on you machine. However as Azure Pipelines is a serverless solution you don't have the same global file to update to include the sources.

Instead of this you need to add a NuGet.config file to the root of your repository.

Here is an example of one set to include Sitecores NuGet package feed.

1<?xml version="1.0" encoding="utf-8"?>
2<configuration>
3 <packageSources>
4 <add key="nuget.org" value="https://www.nuget.org/api/v2/" />
5 <add key="Sitecore NuGet v2 Feed" value="https://sitecore.myget.org/F/sc-packages/" />
6 </packageSources>
7</configuration>

Next you will need to update your pipeline to tell the NuGet step to use this config file

1- task: NuGetCommand@2
2 inputs:
3 restoreSolution: '$(solution)'
4 feedsToUse: 'config'
5 nugetConfigPath: 'NuGet.config'

And that's it. As long as all the sources are correct the NuGet command should now find your packages.