Use NuGet Feed in Azure DevOps Artifacts in DevOps Build Pipeline

As part of our migration to Azure DevOps, we needed to consume a private NuGet feed in our ASP.NET application. Now as we had set up our private NuGet feed using Azure DevOps Artifacts previously, we just needed to get Azure Pipelines to use it.

To do so, I tried to follow articles on to no avail, but eventually came across Travis Illig’s post. I attempted to use Option 1 as the default Azure Pipelines yml file contained a separate restore step.

So the changes I ended up making to the repository are as follows:

1.Added a NuGet.config file with the following content:

<?xml version="1.0" encoding="utf-8"?>
    <add key="disableSourceControlIntegration" value="true" />
    <clear />
    <add key="NuGet Official" value="" protocolVersion="3" />
    <add key="[Name of Feed]" value="https://[organisationName][FeedName]/nuget/v3/index.json" protocolVersion="3" />

Note that we never had a NuGet.config file previously as these particular projects were never configured to run on a build server (yes, terribly bad practice). Also note that Azure DevOps Pipelines doesn’t seem to care what the “Name of Feed” value is.

2. Updated the NuGetCommand@2 task in azure-pipeline.yml file by pointing it to our NuGet.config file:

And that should be it. If you look at the console log of the subsequent build you’ll notice that Azure Pipelines is automatically setting up the credential provider for our private feed based on the feed url.