Updating NuGet packages can be one of those things that's easy to put off. There's always something else to work on. And checking for updates isn't always the most exciting part of development.
Lately I've been giving it a bit more attention, especially with the number of updates and security patches coming out for Umbraco and its dependencies. It's easy to miss something or forget to check when you're juggling multiple projects.
I've written before about automating package updates with GitHub Actions. But we use Azure DevOps for quite a few projects too. So I wanted to be able to do something similar there.
In this article, I'll share how I set up an Azure DevOps pipeline to check for outdated Umbraco packages, update them, and automatically create a Pull Request when changes are found.
The goal is to let the pipeline do the repetitive stuff. But still keep the developers involved in reviewing and approving the updates.
I'm using dotnet outdated for this solution. It's a command-line tool that checks your NuGet dependencies and can tell you what packages have newer versions available.
I've used it before in local PowerShell scripts. Besides checking for updates, it can also automatically update the packages. This makes it perfect for this type of automation.
For example, you can check your solution with:
dotnet outdatedOr update a specific package:
dotnet outdated --upgrade:Auto --include "Umbraco.Cms"I like the option to filter packages. For an Umbraco project, you might want to update the CMS packages separately from Umbraco Forms or other community packages.
I'm also using the --version-lock Major option. This will keep updates within the current major version. So you don't suddenly upgrade from Umbraco 17 to Umbraco 18 with a regular maintenance run.
I prefer to plan and do major upgrades separately.
The main reason is that I don't want package maintenance to depend on someone remembering to do it.
When it's done manually, it's easy to let it end up on the backlog. Other development work gets priority. Before you know it, you're several updates behind.
By making it a part of Azure DevOps, we can make it a part of our normal development workflow.
I've set the pipeline to run every Monday morning. It will check the selected packages, apply available updates, build the solution and create a Pull Request if there are any changes.
If everything is up to date, the pipeline will just finish without creating a PR.
That last part is important. I don't want developers getting unnecessary Pull Requests every week just because the pipeline ran.
The pipeline is made up of a few steps. I'll go over the most important parts before I share the full YAML configuration.
The pipeline will first check out the repository and install the .NET 10 SDK.
It will also check if dotnet-outdated-tool is installed. If so, it will update it. Otherwise, it will install it.
This ensures that we don't rely on an outdated version of the tool being available on the build agent.
The pipeline will create a separate branch before making any changes.
I'm using the Azure DevOps Build ID in the branch name. So each run will get its own branch. For example:
update/umbraco-packages-12345
The pipeline can target develop or main depending on how it's started. I'll explain that option later in the article.
This is where dotnet outdated comes in.
I've added a few parameters to the pipeline. So you can control which packages should be updated:
- Umbraco CMS: Update packages that match Umbraco.Cms.
- Umbraco Forms: Update packages that match Umbraco.Forms.
- Community package: Optionally update a specific community package.
The community package is configurable with a separate parameter. This makes the pipeline reusable without having to change the YAML every time you want to update a different package.
All updates are limited to the current major version.
After updating the packages, the pipeline will build the solution.
I wanted to include this step. Because there's not much point in creating a Pull Request if the updated packages are already causing compilation errors.
Of course, a successful build doesn't mean everything is working correctly. You still need to test the runtime behavior and integrations. But it's a good first check before you ask someone to review the changes.
If the package updates introduced any changes, the pipeline will commit those changes to the update branch and push it to Azure DevOps.
Then it will create a Pull Request against the original target branch.
The PR description will contain the selected packages, the target branch, the date of the update and that the solution successfully built.
If no changes were detected, it will skip this step entirely.
This gives the developers a familiar place to review the changes. Check the updated versions and run any additional tests before merging.
There is one thing that's easy to miss when setting this up: permissions.
By default, the Build Service identity might not have permissions to push changes or create Pull Requests. So we need to give it the necessary permissions first.
Go to:
Project Settings → Repositories → Select your repository → Security
Find the Build Service identity that belongs to your project. It usually has a name like:
<Project Name> Build Service (<Organization>)
Be sure to select the project-specific Build Service identity. Not the Project Collection Build Service Accounts identity.
Give the following permissions:
Permission | Setting |
|---|---|
Read | Allow |
Contribute | Allow |
Create branch | Allow |
Contribute to pull requests | Allow |
These permissions will allow the pipeline to read the repository. Create the update branch. Push the changes. And create a Pull Request.
You don't need to give permission to bypass branch policies. I actually prefer to keep those in place. So the automated PR will follow the same review process as any other change.
There are two things in the YAML that make authentication work.
First, the checkout step has:
- checkout: self
persistCredentials: true
fetchDepth: 0The persistCredentials: true will keep the Git credentials available after checkout. So the subsequent Git commands can push the update branch without the need for a separate Personal Access Token.
For creating the Pull Request, I'm using the built-in System.AccessToken variable.
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)The token is passed as an environment variable to the script. And then used to authenticate against the Azure DevOps REST API.
The actual request looks like this:
curl --fail-with-body --silent --show-error \
-u ":${SYSTEM_ACCESSTOKEN}" \
-H "Content-Type: application/json" \
-X POST \
--data @pr.json \
"$API_URL"No need to create or maintain a separate PAT for this.
One thing to note: you need to explicitly map System.AccessToken into the environment of the pipeline step that needs it. Azure DevOps provides the token. But it's not automatically available as an environment variable in every script.
When you create the pipeline for the first time, Azure DevOps might ask you to authorize access to the repository.
Make sure the pipeline is allowed to access the repository where your solution is located.
If your organization has restricted job authorization scopes, also make sure the project-specific Build Service identity has the required access.
Once you have these permissions in place, the pipeline will be able to create branches. Push changes. And create Pull Requests.
You might wonder why I don't go the extra mile and let the pipeline merge everything automatically.
For me, that would be going too far.
A successful build is a good start. But it doesn't mean the application still behaves as expected. Package updates can introduce changes that are only visible at runtime. Especially with Umbraco projects where packages can interact with custom implementations, property editors, integrations and other dependencies.
I want the developers to still be a part of that process.
The pipeline takes care of finding the updates and preparing the changes. A developer can then review the PR. Check the updated package versions. Run any additional tests before merging.
The goal isn't to remove the developers from the process. It's to remove the repetitive work of maintaining packages.
The weekly schedule is great for regular maintenance. But sometimes you don't want to wait until Monday.
For example, when an important security patch is released. I'd rather get an update ready immediately.
So I've also made the pipeline manually executable.
When you run it manually, you can select the target branch:
develop
main
The scheduled run usually targets develop. But if there's an important security update that needs to be applied to the main branch, you can manually run the pipeline and select main.
You can also select which packages to update during that run. This is useful if you only want to update Umbraco CMS, for example. Without touching Forms or other community packages.
It gives you some flexibility without having to maintain multiple pipelines.
Another thing I've been thinking about lately is how AI is changing software development.
We're becoming much faster at writing code, building features and integrating libraries. That's great. But it also means that applications can have more dependencies and more code to maintain.
At the same time, security vulnerabilities are being discovered and analyzed at an increasing pace. So keeping dependencies up to date is something that I think deserves more attention than it sometimes gets.
I'm not saying that automating NuGet updates is the solution to application security. It's not. You still need proper security reviews, testing, and a sensible release process.
But making sure you regularly check for available updates is a good starting point.
For me, this pipeline is a relatively small improvement that helps prevent package maintenance from being forgotten.
The result is a repeatable process that takes care of something the developers would otherwise have to remember to do themselves.
With this pipeline, we get:
Automatic weekly check for Umbraco package updates
Pull Requests when updates are available.
Build validation before the PR is created.
Control over which packages to update.
Option to target main when an important update needs attention.
Normal review process before merging changes.
It's not a particularly complicated solution. And that's exactly what I like about it.
It uses an existing tool. The Azure DevOps pipeline we already have. And the built-in authentication provided by Azure DevOps.
The next step is to start using it regularly. See how it works across different projects.
Sometimes a little bit of automation is all you need to make routine maintenance a bit easier.
Complete yaml file
trigger: none
pr: none
# --------------------------------------------------
# Weekly schedule
# Monday at 06:00 UTC
# 07:00 CET / 08:00 CEST
# Scheduled runs use the default parameters.
# --------------------------------------------------
schedules:
- cron: '0 6 * * 1'
displayName: 'Weekly Umbraco package updates'
branches:
include:
- develop
always: true
# --------------------------------------------------
# Pipeline parameters
# --------------------------------------------------
parameters:
- name: branch
displayName: 'Branch to update'
type: string
default: 'develop'
values:
- develop
- main
- name: updateCms
displayName: 'Update Umbraco CMS'
type: boolean
default: true
- name: updateForms
displayName: 'Update Umbraco Forms'
type: boolean
default: true
- name: updateCommunity
displayName: 'Update community package'
type: boolean
default: false
- name: communityPackage
displayName: 'Community package NuGet ID'
type: string
default: 'Umbraco.Community.SiteHealth'
pool:
vmImage: 'ubuntu-latest'
variables:
configuration: 'Release'
steps:
# --------------------------------------------------
# 1. Checkout repository
# --------------------------------------------------
- checkout: self
persistCredentials: true
fetchDepth: 0
# --------------------------------------------------
# 2. Install .NET SDK
# --------------------------------------------------
- task: UseDotNet@2
displayName: 'Install .NET SDK'
inputs:
packageType: sdk
version: '10.x'
# --------------------------------------------------
# 3. Install dotnet-outdated
# --------------------------------------------------
- bash: |
set -euo pipefail
if dotnet tool list --global | grep -q 'dotnet-outdated-tool'; then
dotnet tool update --global dotnet-outdated-tool
else
dotnet tool install --global dotnet-outdated-tool
fi
echo "##vso[task.prependpath]$HOME/.dotnet/tools"
dotnet outdated --version
displayName: 'Install dotnet-outdated'
# --------------------------------------------------
# 4. Create update branch
# --------------------------------------------------
- bash: |
set -euo pipefail
git config user.email "build-service@local"
git config user.name "Azure DevOps Build Service"
echo "Branch to update: ${BRANCH_TO_UPDATE}"
git fetch origin "${BRANCH_TO_UPDATE}"
BRANCH="update/umbraco-packages-$(Build.BuildId)"
git checkout -B "$BRANCH" "origin/${BRANCH_TO_UPDATE}"
TIMESTAMP=$(TZ=Europe/Amsterdam date '+%Y-%m-%d %H:%M %Z')
echo "##vso[task.setvariable variable=updateBranch]$BRANCH"
echo "##vso[task.setvariable variable=runTimestamp]$TIMESTAMP"
echo "Created update branch: $BRANCH"
echo "Update timestamp: $TIMESTAMP"
displayName: 'Create update branch'
env:
BRANCH_TO_UPDATE: ${{ parameters.branch }}
# --------------------------------------------------
# 5. Update selected NuGet packages
# --------------------------------------------------
- bash: |
set -euo pipefail
SOLUTION=$(find . -name '*.sln' -not -path '*/obj/*' -print -quit)
if [ -z "$SOLUTION" ]; then
echo "No solution file found!"
exit 1
fi
echo "Using solution: $SOLUTION"
# Convert boolean parameters to lowercase
UPDATE_CMS_LOWER=$(echo "$UPDATE_CMS" | tr '[:upper:]' '[:lower:]')
UPDATE_FORMS_LOWER=$(echo "$UPDATE_FORMS" | tr '[:upper:]' '[:lower:]')
UPDATE_COMMUNITY_LOWER=$(echo "$UPDATE_COMMUNITY" | tr '[:upper:]' '[:lower:]')
# Umbraco CMS
if [ "$UPDATE_CMS_LOWER" = "true" ]; then
echo "Updating Umbraco CMS packages..."
dotnet outdated "$SOLUTION" \
--upgrade:Auto \
--version-lock Major \
--include "Umbraco.Cms"
fi
# Umbraco Forms
if [ "$UPDATE_FORMS_LOWER" = "true" ]; then
echo "Updating Umbraco Forms packages..."
dotnet outdated "$SOLUTION" \
--upgrade:Auto \
--version-lock Major \
--include "Umbraco.Forms"
fi
# Community package
if [ "$UPDATE_COMMUNITY_LOWER" = "true" ]; then
if [ -z "$COMMUNITY_PACKAGE" ]; then
echo "Community package ID cannot be empty!"
exit 1
fi
echo "Updating community package: $COMMUNITY_PACKAGE"
dotnet outdated "$SOLUTION" \
--upgrade:Auto \
--version-lock Major \
--include "$COMMUNITY_PACKAGE"
fi
echo "Package updates completed."
displayName: 'Update selected packages'
env:
UPDATE_CMS: ${{ parameters.updateCms }}
UPDATE_FORMS: ${{ parameters.updateForms }}
UPDATE_COMMUNITY: ${{ parameters.updateCommunity }}
COMMUNITY_PACKAGE: ${{ parameters.communityPackage }}
# --------------------------------------------------
# 6. Build solution
# --------------------------------------------------
- bash: |
set -euo pipefail
SOLUTION=$(find . -name '*.sln' -not -path '*/obj/*' -print -quit)
if [ -z "$SOLUTION" ]; then
echo "No solution file found!"
exit 1
fi
echo "Building: $SOLUTION"
dotnet build "$SOLUTION" \
--configuration "$(configuration)"
displayName: 'Build solution'
# --------------------------------------------------
# 7. Commit and push changes
# --------------------------------------------------
- bash: |
set -euo pipefail
git add -A
if git diff --cached --quiet; then
echo "No package updates found."
echo "##vso[task.setvariable variable=hasChanges]false"
exit 0
fi
COMMIT_TITLE="chore: update Umbraco packages - $(runTimestamp)"
git commit -m "$COMMIT_TITLE"
git push origin "$(updateBranch)"
echo "##vso[task.setvariable variable=hasChanges]true"
displayName: 'Commit and push changes'
# --------------------------------------------------
# 8. Create pull request
# --------------------------------------------------
- bash: |
set -euo pipefail
TIMESTAMP="$(runTimestamp)"
jq -n \
--arg source "refs/heads/$(updateBranch)" \
--arg target "refs/heads/${BRANCH_TO_UPDATE}" \
--arg title "chore: update Umbraco packages - ${TIMESTAMP}" \
--arg timestamp "$TIMESTAMP" \
--arg branch "$BRANCH_TO_UPDATE" \
--arg cms "$UPDATE_CMS" \
--arg forms "$UPDATE_FORMS" \
--arg community "$UPDATE_COMMUNITY" \
--arg package "$COMMUNITY_PACKAGE" \
'{
sourceRefName: $source,
targetRefName: $target,
title: $title,
description: (
"Automated Umbraco NuGet package update.\n\n" +
"Updated: " + $timestamp + "\n\n" +
"Target branch: " + $branch + "\n\n" +
"Selected packages:\n" +
"- Umbraco CMS: " + $cms + "\n" +
"- Umbraco Forms: " + $forms + "\n" +
"- Community package: " + $community + "\n" +
"- Community package ID: " + $package + "\n\n" +
"All package updates are restricted to the current major version.\n\n" +
"The solution has been built successfully.\n\n" +
"Please review the changes before merging."
)
}' > pr.json
API_URL="${COLLECTION_URI}${PROJECT_ID}/_apis/git/repositories/${REPOSITORY_ID}/pullrequests?api-version=7.1"
echo "Creating pull request..."
echo "Update branch: $(updateBranch)"
echo "Target branch: ${BRANCH_TO_UPDATE}"
echo "Timestamp: ${TIMESTAMP}"
RESPONSE=$(curl --fail-with-body --silent --show-error \
-u ":${SYSTEM_ACCESSTOKEN}" \
-H "Content-Type: application/json" \
-X POST \
--data @pr.json \
"$API_URL")
echo "$RESPONSE" | jq -r '"Pull request created: " + .url'
displayName: 'Create pull request'
condition: and(succeeded(), eq(variables['hasChanges'], 'true'))
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
COLLECTION_URI: $(System.CollectionUri)
PROJECT_ID: $(System.TeamProjectId)
REPOSITORY_ID: $(Build.Repository.ID)
BRANCH_TO_UPDATE: ${{ parameters.branch }}
UPDATE_CMS: ${{ parameters.updateCms }}
UPDATE_FORMS: ${{ parameters.updateForms }}
UPDATE_COMMUNITY: ${{ parameters.updateCommunity }}
COMMUNITY_PACKAGE: ${{ parameters.communityPackage }}