Automate Nuget Package Upgrade In Azure Pipelines

One of the challenges faced by most of the projects is to keep up-to-date Nuget version for source code. It can be time consuming process and a repetitive job to update the version manually. Also, when we use private Nuget packages from Azure Artifacts as Nuget feed into our project, and we are frequently modifying those packages version, in that case maintainability becomes a headache due to dependency.

This article demonstrates how can we automate NuGet Package updates for a project in Azure DevOps CI pipeline.

We will use NuKeeper free extension run from a CI pipeline in Azure DevOps to automate this process to a large extent.

Nukeeper is a .net CLI tool that can be used for updating Nuget packages It will automatically change your package versions and create a pull request with the new changes. Also, we can automatically validate code by pre-merging and building pull request changes as part of build validation.

Let’s see below step-by-step implementation,

STEP 1 – Installation of NuKeeper

We will install Nukeeper extension from Organization settings in Azure Devops. Browse the marketplace and select Nukeeper.

Automate Nuget Package Upgrade In Azure Pipelines

STEP 2 – Set Repositories permission from Project Settings

Certain permission needs to be allowed for project build service to create branch and create a PR. Go to Project Settings -> All Repositories -> Security and allow Contribute, contribute to pull request, and create branch. Make sure that Create tag and read options are allowed.

STEP 3 – Setup a new CI Pipeline

We will create a new CI pipeline using classic editor for Nukeeper.

Automate Nuget Package Upgrade In Azure Pipelines

At this point, we just choose the default empty job template. Now check this option Allow scripts to access the OAuth token.

Automate Nuget Package Upgrade In Azure Pipelines

STEP 4 - Add NuKeeper task in CI Pipeline

Add “NuKeeper” as task and select the Azure Artifacts feed.

Automate Nuget Package Upgrade In Azure Pipelines

Nukeeper arguments are one of the important params. For example, if we don’t want a specific package to be upgraded, we can mention like --exclude Microsoft.EntityFrameworkCore

For more arguments, please refer here.

Now Save the pipeline.

STEP 5 – Test and Scheduling Checks

Now we can run the pipeline. It will create PR for each package that are upgrading the version.

Automate Nuget Package Upgrade In Azure Pipelines

Automate Nuget Package Upgrade In Azure Pipelines

Under the Triggers tab we can set a schedule as to when to run the pipeline.

Awesome! We have seen how we can use NuKeeper and Azure Pipelines to automate the process of updating NuGet packages. Hope you found this article useful.

Happy Learning!


Similar Articles