Internal NuGet feed with Azure DevOps (VSTS)

Imagine you have some tools or a framework you want to share with your company and reuse it on various projects. If you develop your tool in .Net standard, then you are in luck. Creating a NuGet package has never been easier.

Make your library a NuGet

For the sake of this demo, I will make a simple project.

Now we have to configure this project, so we get a .nupkg file as a build output.

Option 1: Project Properties – package

Make sure to check Generate NuGet package on build. Then you can fill whatever info you need for your package.

Option 2: Edit csproj

Now when we build our solution or the project we receive the .nupkg as an output.

Setup build and release pipeline

I assume you have some basic experience with Azure DevOps (VSTS). If not, here is a quick how to.

Build pipeline

  1. Use Nuget 4.3.0
  2. Nuget restore
  3. Build solution (Visual studio build)
  4. Copy files to $(build.artifactstagingdirectory)
    • By default, .nupkg(s) are not part of the publish artifacts
    • Contents = **/*.nupkg
    • Target folder = $(build.artifactstagingdirectory)
  5. Publish Artifact: drop
Step by step build pipeline creation

NuGet feed

Before we create our release pipeline, we need to create a Nuget feed. Navigate to Artifacts and click on “New feed” button. Give it a name and you are ready to go.

Step by step NuGet feed creation

Release pipeline

Our pipeline will simply deliver all .nupkg(s) to our NuGet feed which we created in previous step.

Step by step release pipeline creation

Now your release pipeline will automatically trigger every time your build pipeline is successful. And this is how the output looks like.

Side note

I had to change my PackageId from Calculator to BadDemoCalculator. Because the first release pipeline gave me a following warning:

‘Calculator 1.0.0’ cannot be published to the feed because it exists in at least one of the feed’s upstream sources. Publishing this copy would prevent you from using ‘Calculator 1.0.0’ from ‘nuget.org’. For more information, see https://go.microsoft.com/fwlink/?linkid=864880

It is caused by selecting this option:

It is wise to have this option selected, because typically you won’t have conflicts with existing packages. Also, when you use this NuGet feed in your build pipelines, you don’t have to use nuget.org explicitly.

Leave a Reply