{
  "$type": "site.standard.document",
  "canonicalUrl": "https://johnnyreilly.com/posts/azure-devops-consume-private-nuget-artifact-feed",
  "description": "To build applications both locally and in an Azure Pipeline using Private Azure Artifact feeds with Azure DevOps, follow these steps.",
  "path": "/posts/azure-devops-consume-private-nuget-artifact-feed",
  "publishedAt": "2022-03-30T00:00:00.000Z",
  "site": "at://did:plc:yy3apqjlms24kso7ahn7lbmb/site.standard.publication/3mova7c4nho2b",
  "tags": [
    "azure devops",
    "asp.net"
  ],
  "textContent": "Private Azure Artifact feeds in in Azure DevOps can be used to serve NuGet packages. To build applications both locally and in an Azure Pipeline using those packages, there are a few steps to follow which this post will demonstrate.\n\n\n\nMake a nuget.config\n\nTo consume a private feed, you'll likely want to create a nuget.config file in the root of your repo. Here you list the package sources you want to consume, typically the NuGet official package source _as well_ as your private feed. See the example below:\n\nConsuming a private feed locally with the Azure Artifacts Credential Provider\n\nWith our nuget.config in place, can we build locally? Yes, once we've authenticated. If you're using Rider or Visual Studio, these may take care of this for you. However, if you're using VS Code you might need to do something else.\n\nIf you experience 401's when you run dotnet restore like so:\n\nThen it's probably a sign you need to install the Azure Artifacts Credential Provider. With that you should be able to restore nuget packages. See instructions here.\n\nOn Linux and Mac this is as simple as running sh -c \"$(curl -fsSL https://aka.ms/install-artifacts-credprovider.sh)\" in your terminal.\n\nSubsequently, running dotnet restore --interactive should trigger an authentication flow in the terminal, and subject to successful authentication, restore packages from the private feed.\n\nConsuming a private feed in Azure Pipelines\n\nYou will need to authenticate within your pipeline before you can acquire your private feed packages. This is as simple as this:\n\nBefore building / publishing or running tests, you must first explicitly dotnet restore and provide the path to the nuget.config. You can do this with the dedicated .NET Core CLI task task like so:\n\nThe publish gotcha\n\nOn occasion, it can happen that Azure Pipelines doesn't seem to be happy running a publish task with private feeds. Consider, a task like this:\n\nThis can result in non-actionable errors like this:\n\n> ##[error]Error: There was an error when attempting to execute the process '/opt/hostedtoolcache/dotnet/dotnet'. This may indicate the process failed to start. Error: spawn /opt/hostedtoolcache/dotnet/dotnet ENOENT\n\nA workaround in this situation is to invoke .NET through a bash script directly like so:\n\nAnd note that after publishing we use the Archive Files task to zip up the output of our publishing.\n\nYou may be tempted to use the zip command line utility to make your zip. Do not do this. I did this. I learned, through no small amount of suffering, that there is a problem with this. Whilst you can make a zip this way that will be consumed happily by Mac and OSX, when it comes to being deployed to Azure (even if you're deploying to Linux within Azure) via zip deploy it will not work. I can't tell you why, just that it won't. So use the dedicated task.\n\nSumming up\n\nAnd that's it; with these approaches in place you should be able to build applications consuming privage NuGet feeds with ease.",
  "title": "Azure DevOps: consume a private artifact feed"
}