InnerWorks Logo
Return to main siteReturn to main site
Blogs

How to Set up a Private NuGet Feed With Azure or Any Service Provider

How to Set up a Private NuGet Feed With Azure or Any Service Provider

Adrian Ochmann • Back-end Developer

from Cogworks • 21 May 2024 • 1 min read

Consider this blog post a continuation of the “old but good” tech tutorial ‘How to Setup a Private NuGet Feed in Azure DevOps Pipelines’ (In the old Cogblog Archive). In an interesting twist: you can now authenticate to an external or internal Azure DevOps NuGet feed using a script!

Working with package managing solutions, I've found GitHub Packages handy. It's straightforward, centralised, and cost-effective. Configuring and publishing npm packages with GitHub is easy.

In this post, I’ll cover:

  1. How to set up a private NuGet feed with Azure DevOps
  2. How to set up a Private NuGet Feed using Docker.
  3. How to Setup a Private NuGet feed with any service provider.

Let’s go!

1. How to set up a private NuGet feed with Azure DevOps

Step 1

Before you start, generate a PAT (personal access token)  token; find out how to develop a PAT with Azure here.

Step 2

Install your relevant credentials provider. You need to install your relevant Azure DevOps credit providers:
For PowerShell users
For Bash users

Step 3

Add your private NuGet feed to the NuGet.config file like this:
- Azure DevOps: https://pkgs.dev.azure.com/NAMESPACE/nuget/v3/index.json

Step 4

Export to the environment variable
Use your private NuGet feed URL as shown below:

VSS_NUGET_EXTERNAL_FEED_ENDPOINTS={"endpointCredentials": [{"endpoint":"[your_private_nuget_feed_url]", "username":"[user]", "password":"[PAT]"}]}

And that’s it! You can now work in the external feed based on your generated PAT.

2. How to Setup A Private NuGet Feed using Docker

Step 1 - How to set up a Dockerfile (docker build process) access to an external feed on Azure DevOps.

 

FROM mcr.microsoft.com/dotnet/sdk:7.0-bullseye-slim AS build-env

WORKDIR /source

# Private NuGet Artefact steps

# Install NuGet Credentials manager

RUN wget https://raw.githubusercontent.com/Microsoft/artifacts-credprovider/master/helpers/installcredprovider.sh \

    && chmod +x installcredprovider.sh \

    && ./installcredprovider.sh

 

ARG NUGET_PAT

ENV VSS_NUGET_EXTERNAL_FEED_ENDPOINTS "{\"endpointCredentials\": [{\"endpoint\": \"[your_private_nuget_feed_url]\",\"username\": \"CI Build\",\"password\": \"${NUGET_PAT}\"}]}"

 

# Copy all files

COPY . .

# Restore NuGet dependencies

RUN dotnet restore

And that’s all you need to do. You should now be able to authorise the external NuGet feed using Docker!

How to Setup a Private NuGet feed with any service provider

This method uses dotnet nuGet CLI to create a source with your chosen PAT token.

Step 1

Generate your PAT (Personal Access Token) using your chosen service provider. For both automatic and manual, you’ll need to create PAT first.

We’ve included PAT generation instructions for the leading providers below, GitHub and MyGet, but you can use anything you like.

GitHub PAT instructions
MyGet PAT instructions
Azure DevOps PAT instructions 

The automatic (CLI) way:

Using this method, you can add your provider, GitHub or MyGet.
dotnet nuget add source [your_private_nuget_feed_url] --name PRIVATE_SOURCE_NAME --username BUILD_CI --password BASE64_PAT --store-password-in-clear-text --configfile NuGet.config

The manual way (NuGet.config):

This is for manually adding a new source with a PAT token. 

That's it!

We’re always keen to know if there are any developer tutorials you’d like to read. So what are you waiting for? Let us know what you want to hear next on social media, and we’ll whip something up.

Community tech aid

Innerworks and Cogworks are proud to partner with Community TechAid who aim to enable sustainable access to technology and skills needed to ensure digital inclusion for all. Any support you can give is hugely appreciated.