NuGet Package Automation
Quick-lookup for automating NuGet package upgrades in .NET projects with NuKeeper, plus authenticating against an Azure DevOps feed. For engineers maintaining package versions across many repositories.
Quick Navigation
| Task | Section |
|---|---|
| Inspect versions and automate upgrade pull requests | NuKeeper Inspection and Upgrades |
| Authenticate against an Azure DevOps feed | Azure DevOps Feed Authentication |
NuKeeper Inspection and Upgrades
NuKeeper covers the following package-maintenance tasks:
- Automate the generation of pull requests for nuget package upgrades.
- Report the volume of projects that will be impacted by a library repository change (AKA roll out impact).
- Report on all the versions of a specific library. E.g. Newtonsoft.
- Identify missing analyzers in solutions. E.g. SonarQube.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Start-Process https://dev.azure.com/<your-org>/_usersSettings/tokens
$PersonalAccessToken = 'DO-NOT-SAVE-THIS-TO-CODE-REPOSITORY'
dotnet tool install nukeeper --global
nukeeper --help
nukeeper global -h
nukeeper inspect --exclude Fody
nukeeper inspect --include Analyzers
nukeeper inspect --useprerelease Always --logfile c:\Temp\nukeeper.log --include <package-prefix>.
nukeeper inspect --useprerelease Always --logfile c:\Temp\nukeeper.log --include <package-prefix>. --change Major --source https://pkgs.dev.azure.com/<your-org>/<project>/_packaging/<feed>/nuget/v3/index.json
# Reboot your Powershell console after setting the token.
[System.Environment]::SetEnvironmentVariable('Nukeeper_azure_devops_token', $PersonalAccessToken,[System.EnvironmentVariableTarget]::Machine)
# Practically, this setting doesn't seem to inject itself as expected on build servers.
Azure DevOps Feed Authentication
Register a NuGet feed source with a personal access token (PAT), then iterate repositories to raise consolidated upgrade pull requests.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Create a PAT with the appropriate read artifacts permissions
#Start-Process https://dev.azure.com/<your-org>/_usersSettings/tokens
# Update an existing source (which should be configured in nuget.config to enable new engineers to quick reference the nuget package sources needed)
$PersonalAccessToken = 'DO-NOT-SAVE-THIS-TO-CODE-REPOSITORY'
# Use the add when setting up for the first time
nuget sources add -name <feed-name> -source https://pkgs.dev.azure.com/<your-org>/_packaging/<feed>/nuget/v3/index.json -username AzDO -password $PersonalAccessToken
# Use the update operation when you update the PAT token.
# nuget sources add -name <feed-name> -source https://pkgs.dev.azure.com/<your-org>/_packaging/<feed>/nuget/v3/index.json -username AzDO -password $PersonalAccessToken
# Create a PAT with the appropriate read artifacts permissions
#Start-Process https://dev.azure.com/<your-org>/_usersSettings/tokens
# Set up the environment variable for the AZ CLI
$env:AZURE_DEVOPS_EXT_PAT = 'DO-NOT-SAVE-THIS-TO-CODE-REPOSITORY'
# Use the PAT for this script
$PersonalAccessToken = 'DO-NOT-SAVE-THIS-TO-CODE-REPOSITORY'
# Retrieve a list the repository URL's and create all the pull requests - minor nuget changes.
$repos = az repos list --org https://dev.azure.com/<your-org>/ --project <project> | ConvertFrom-Json | Select-Object webURL
# Assumption: Git Flow branching strategy
foreach ($repo in $repos) {
C:\Users\$ENV:USERNAME\source\nukeeper\NuKeeper\bin\Debug\net5.0\nukeeper.exe repo $repo.webURL $PersonalAccessToken --change minor --verbosity detailed --branchnametemplate "feature/{Default}" --consolidate --maxpackageupdates 10 --targetBranch "develop"
}
This post is licensed under
CC BY 4.0
by the author.