Private NuGet Feed

Published on Saturday, 14 March 2020

As a .NET developer you probably use NuGet everyday, or something from it.

NuGet

What is NuGet?

NuGet is the package manager for .NET. The NuGet client tools provide the ability to produce and consume packages. The NuGet Gallery is the central package repository used by all package authors and consumers.

This is great for consuming other peoples libraries, even your own, if they can be public, but there are times you may wish to have a Private feed. Luckily there are options. One is hosting it yourself on your Azure Dev Ops (ADO) instance.

To do this create a new Project:

Then create a new Repo:

Click on the "Artifacts" tab

old https://[TENANT].visualstudio.com/[PROJECT]/_packaging?_a=feed&feed=[FEEDNAME] new https://[TENANT].azure.com/[PROJECT]/_packaging?_a=feed&feed=[FEEDNAME]

Click "+ Create Feed".

Give it a "Name", set it's Visibility as you might only allow certain Users in the Org to see it, and decide if you want to include "Upstream sources".

Next we can create a Pipeline.

PipeLines

Create a new Pipeline:

trigger:
- master

pool:
  vmImage: '[CHOOSE]'

steps:
- script: echo Hello, world!
  displayName: 'Run a one-line script'

- task:
  [TODO]

You can decide which branches will trigger the pipeline to run.

You can pick an image to run your build on.

Next there is a publish step you can use, on the right hand side of the page there will either be a "Show assistant" button or a column of tasks.

Search for "NuGet"

Command: "push"

Path to NuGet package(s) to publish: "\((Build.ArtifactStagingDirectory)/**/*.nupkg;!\)(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg"

Target feed location: This organization/collection

Target feed: Choose from a picker.

- task: NuGetCommand@2
  inputs:
    command: 'push'
    packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg'
    nuGetFeedType: 'internal'
    publishVstsFeed: '[GUID]'

The publishVstsFeed can either be a GUID or the name of the feed. When using the GUI it usually adds the underlying Guid.

I've skipped the other tasks needed, your code would need to be Built then packed etc.