Home / Guides / Find outdated internal NuGet package versions
Find projects that pin different or outdated versions of your internal NuGet packages
You publish a fix to an internal package, and weeks later one app still restores the version from last spring. Another package is pinned at four different versions across your repositories. Nothing fails, so nobody notices until a bug that was fixed long ago turns up in production. This guide shows how to see it: the .NET SDK's own outdated check, a PowerShell script that reads every project file under your clone folders and lists who is behind and which packages are pinned at several versions, and where doing it by hand stops.
Short answer.
Per solution, dotnet package list --outdated asks your feed what is newer than each project's reference. Across many repositories
there is no single command: read the version out of every PackageReference (and out of Directory.Packages.props when you
use central package management), group by package, and compare each pin with the highest one and with the version in the package's own project file.
Being behind the newest version is not always wrong: some projects stay on an old version on purpose. The list tells you where to look, not what to change.
Step 1: ask the feed, one solution at a time
The SDK compares what a project references with what the NuGet sources offer. In .NET 10 the command is dotnet package list; with the
.NET 9 SDK or earlier write dotnet list package. The Requested column is what the project file asks for, Resolved
is what it actually uses, and Latest is the newest version on the source:
# .NET 10 SDK, from the folder of a solution; --source is your own feed (made-up address)
dotnet package list --outdated --source https://pkgs.dev.azure.com/contoso/Tools/_packaging/internal/nuget/v3/index.json
# same major version only
dotnet package list --outdated --highest-minor --source https://pkgs.dev.azure.com/contoso/Tools/_packaging/internal/nuget/v3/index.json
# .NET 9 SDK or earlier
dotnet list package --outdated --source https://pkgs.dev.azure.com/contoso/Tools/_packaging/internal/nuget/v3/index.json
--source(or--config) says where to look for newer versions, and needs--outdated. Without it the command uses the sources from yournuget.config.--highest-minorand--highest-patchhold the comparison to the same major (or major.minor) version, which is usually what you want for an internal package whose next major version needs code changes.- Since .NET 10 the command restores first if it needs to, so it can write the
objfolder and needs access to your feed.--no-restoreskips that, but then the repository must already be restored. --format jsongives output a script can read. Add--include-prereleaseonly if your internal packages publish previews you want to count.
To run it over every solution in a folder of clones and keep only your own packages:
$feed = 'https://pkgs.dev.azure.com/contoso/Tools/_packaging/internal/nuget/v3/index.json'
Get-ChildItem C:\Repos -Recurse -File -Include *.sln, *.slnx |
Where-Object { $_.FullName -notmatch '\\(bin|obj|node_modules)\\' } |
ForEach-Object {
"== $($_.FullName)"
dotnet package list --project $_.FullName --outdated --source $feed | Select-String 'Contoso\.'
}
That answers "is a newer version published?". It does not answer "which of my repositories are the odd ones out?", it is one solution at a time, and a repository that has not been restored on this machine costs a restore each. Two more questions need a different tool.
Step 2: read the project files across all repositories
Reading the files answers two questions without touching the feed: which packages are pinned at several different versions, and which projects pin a version lower than the one in the package's own project file. The second one catches the repository where the package was fixed and its version bumped, while the consumers have not moved yet.
The script reads:
PackageReferenceentries in.csproj,.vbprojand.fsprojfiles: theVersionattribute or child element, orVersionOverridewhen central package management is on.PackageVersionentries inDirectory.Packages.props. When a project has aPackageReferencewithout a version, the version comes from the nearest such file going up the folders, as NuGet does.- The
Version(orVersionPrefix) of each project that publishes a package, as the version "in source".
Save it as C:\Scripts\Find-PinnedVersions.ps1:
param(
[string[]]$Root = @('C:\Repos'),
[string[]]$Prefix = @('Contoso.') # the start of your own package ids
)
$skip = '\\(bin|obj|node_modules|packages|\.git|\.vs)\\'
$isInternal = { param($name) foreach ($p in $Prefix) { if ($name -like "$p*") { return $true } }; $false }
# "1.2.3" or "1.2.3-beta.1" become comparable; floating (1.*), ranges and $(Property) values give $null
function ConvertTo-Pin([string]$text) {
if ($text -notmatch '^(\d+(?:\.\d+){0,3})(-[0-9A-Za-z.-]+)?(\+.*)?$') { return $null }
$parts = @($Matches[1].Split('.'))
$pre = [bool]$Matches[2]
while ($parts.Count -lt 3) { $parts += '0' }
[pscustomobject]@{ Text = $text; Version = [version]($parts -join '.'); Pre = $pre }
}
function Test-Behind($pin, $source) {
$c = $pin.Version.CompareTo($source.Version)
$c -lt 0 -or ($c -eq 0 -and $pin.Pre -and -not $source.Pre)
}
function Read-Xml($file) {
try { [xml](Get-Content -LiteralPath $file.FullName -Raw) }
catch { Write-Warning "Not readable: $($file.FullName)"; $null }
}
$files = @(foreach ($r in $Root) {
Get-ChildItem -Path $r -Recurse -File -Include *.csproj, *.vbproj, *.fsproj, Directory.Packages.props -ErrorAction SilentlyContinue |
Where-Object { $_.FullName -notmatch $skip }
})
# 1. Central package versions: folder -> (package id -> version text). The nearest file above a project applies.
$central = @{}
foreach ($f in @($files | Where-Object Name -eq 'Directory.Packages.props')) {
$xml = Read-Xml $f; if (-not $xml) { continue }
$map = @{}
foreach ($n in $xml.SelectNodes('//*[local-name()="PackageVersion"]')) {
$id = $n.GetAttribute('Include'); $v = $n.GetAttribute('Version')
if ($id -and $v -and -not $map.ContainsKey($id)) { $map[$id] = $v } # conditions are not evaluated: first entry wins
}
$central[$f.DirectoryName] = $map
}
function Get-CentralMap([string]$dir) {
while ($dir) { if ($central.ContainsKey($dir)) { return $central[$dir] }; $dir = Split-Path -Parent $dir }
}
# 2. Projects: the version each package has in source, and every reference with the version it asks for.
$producers = @{}
$refs = [System.Collections.Generic.List[object]]::new()
foreach ($f in @($files | Where-Object Name -ne 'Directory.Packages.props')) {
$xml = Read-Xml $f; if (-not $xml) { continue }
foreach ($n in $xml.SelectNodes('//*[local-name()="PackageReference"]')) {
$id = $n.GetAttribute('Include').Trim()
if (-not $id -or $id -match '\$\(') { continue }
$ver = $n.GetAttribute('VersionOverride')
if (-not $ver) { $ver = $n.GetAttribute('Version') }
if (-not $ver) { $child = $n.SelectSingleNode('*[local-name()="Version"]'); if ($child) { $ver = $child.InnerText.Trim() } }
if (-not $ver) { $map = Get-CentralMap $f.DirectoryName; if ($map -and $map.ContainsKey($id)) { $ver = $map[$id] } }
$refs.Add([pscustomobject]@{ Id = $id; Version = $ver; From = $f.FullName })
}
$value = { param($tag) @($xml.SelectNodes("//*[local-name()='$tag']") | ForEach-Object { $_.InnerText.Trim() }) |
Where-Object { $_ -and $_ -notmatch '\$\(' } | Select-Object -First 1 }
$packable = & $value 'IsPackable'
if ($packable -eq 'false') { continue }
$pkgId = & $value 'PackageId'
if (-not ($pkgId -or (& $value 'GeneratePackageOnBuild') -eq 'true' -or $packable -eq 'true')) { continue }
if (-not $pkgId) { $pkgId = & $value 'AssemblyName' }
if (-not $pkgId) { $pkgId = $f.BaseName }
$src = & $value 'Version'
if (-not $src) { $src = & $value 'VersionPrefix' }
$producers[$pkgId] = $src
}
# 3. Per internal package: pins behind the source version, and several different pins.
$internal = @($refs | Where-Object { & $isInternal $_.Id })
$report = foreach ($g in @($internal | Group-Object Id)) {
$srcText = $producers[$g.Name]
$srcPin = if ($srcText) { ConvertTo-Pin $srcText }
$pins = @()
foreach ($r in $g.Group) {
if (-not $r.Version) { continue }
$pin = ConvertTo-Pin $r.Version
if (-not $pin) {
[pscustomobject]@{ Package = $g.Name; Finding = 'Floating, ranged or property version'; Pinned = $r.Version; Project = $r.From }
continue
}
$pins += [pscustomobject]@{ Pin = $pin; From = $r.From }
if ($srcPin -and (Test-Behind $pin $srcPin)) {
[pscustomobject]@{ Package = $g.Name; Finding = "Behind source version $srcText"; Pinned = $r.Version; Project = $r.From }
}
}
$byVersion = @($pins | Group-Object { $_.Pin.Text } | Sort-Object { $_.Group[0].Pin.Version } -Descending)
if ($byVersion.Count -gt 1) {
[pscustomobject]@{
Package = $g.Name
Finding = 'Pinned at several versions'
Pinned = ($byVersion | ForEach-Object { "$($_.Name) x$($_.Count)" }) -join ', '
Project = (@($byVersion | Select-Object -Skip 1 | ForEach-Object { $_.Group.From }) | Sort-Object -Unique) -join '; '
}
}
}
$report | Sort-Object Package, Finding, Project
Run it with the folders where your repositories are cloned and the start of your own package ids:
C:\Scripts\Find-PinnedVersions.ps1 -Root C:\Repos -Prefix 'Contoso.' | Format-Table -AutoSize -Wrap
# several clone folders and two prefixes, saved for a spreadsheet:
C:\Scripts\Find-PinnedVersions.ps1 -Root C:\Repos, D:\Work -Prefix 'Contoso.', 'Fabrikam.' |
Export-Csv C:\Temp\pinned-versions.csv -NoTypeInformation
With made-up package names, the result looks like this:
Package Finding Pinned Project
------- ------- ------ -------
Contoso.Core Behind source version 2.4.0 1.9.3 C:\Repos\Legacy\Legacy.csproj
Contoso.Core Behind source version 2.4.0 2.1.0 C:\Repos\Alerts\Alerts.csproj
Contoso.Core Pinned at several versions 2.4.0 x2, 2.1.0 x1, 1.9.3 x1 C:\Repos\Alerts\Alerts.csproj; C:\Repos\Legacy\Legacy.csproj
Contoso.Data Floating, ranged or property version 3.* C:\Repos\Api\Api.csproj
- Pinned behind the source version: the project pins a version lower than the one in the package's project file. If the source version has not been published yet this is normal; if it has, the consumer needs to update.
- Pinned at several versions: at least two different versions are in use across the scanned projects. The project column lists the projects that are not on the highest one.
- Floating, ranged or property version: values such as
1.*,[1.0,2.0)or$(CoreVersion)cannot be compared as text, so they are listed and left out of the other two findings.
Package ids are compared without regard to case, as NuGet does, and a version with a pre-release label counts as lower than the same version without one. A project file that is not valid XML is reported as a warning and skipped. The script only reads files.
Step 3: decide what to do with each finding
- Behind, and the newer version is on the feed: update the reference in that repository, build, run its tests, and release it like any other change.
- Behind, and the newer version is not on the feed yet: the package was bumped but not published. Nothing for the consumers to do; check the producer's pipeline.
- Several versions, no reason: pick the version you want everywhere. Central package management, with one
Directory.Packages.propsper repository, stops the drift inside a repository. It cannot span repositories, so across repositories the list above is the check you repeat. - Pinned low on purpose: write down why next to the reference, so the next scan does not send someone chasing it.
Common problems
- A reference shows no version. It is a
PackageReferencewithout aVersionand there is noDirectory.Packages.propsabove it, or the version is set in a.propsfile the script does not read. Such references are skipped. - The same package has different versions per target framework. With central package management you can give one package different versions
under conditions. The script does not evaluate conditions: it takes the first
PackageVersionit finds for the id. - A
VersionOverrideon a reference. It takes precedence over the central version, and the script reads it first. - Restore uses a higher version than the one in the file. A version in a
PackageReferencemeans "this version or higher", and another package in the graph can pull in a newer one.dotnet package listshows both columns, Requested and Resolved; the script only knows what the file asks for.
Where doing it by hand stops
- Text, not MSBuild. Conditions, properties and imports are not evaluated, and versions in
Directory.Build.propsor other shared files are not read. - Two tools for two questions. The script never contacts the feed, so it cannot say what is newest there;
dotnet package listdoes, but only per solution. - Only what you cloned. A repository that is not under the folders you scan is invisible, and so are the packages it uses.
- A snapshot. It is right on the day you run it, and somebody has to remember to run it again.
Questions
How do I find outdated NuGet packages in a .NET solution?
Run dotnet package list --outdated from the solution folder (dotnet list package --outdated with the .NET 9 SDK or earlier). It compares each project's reference with the newest version on your NuGet sources; add --source for your own feed and --highest-minor to stay within the same major version.
Does dotnet package list --outdated work across many repositories?
No. It works on one project or solution at a time, and since .NET 10 it restores first unless you pass --no-restore. To compare many repositories, loop over the solutions, or read the PackageReference entries from the project files and group them by package.
How do I see which projects use different versions of the same package?
Read the version of every PackageReference, and the PackageVersion entries in Directory.Packages.props when you use central package management, then group by package id and look for ids with more than one version. The script in this guide does that for the packages whose ids start with your prefix.
Does central package management stop version drift?
Inside one repository, mostly: the versions are in one Directory.Packages.props, although a project can still use VersionOverride on a reference unless you turn that off with CentralPackageVersionOverrideEnabled. Across repositories it does nothing, because each repository has its own file.
Does Switchyard show projects pinned to old versions of internal packages?
Yes, for the projects under the folders you scan: its Versions tab and switchyard-cli versions list consumers pinned behind the version in source and packages pinned at many different versions. The optional Needs update check also asks your Azure DevOps feed whether a reference pins less than the newest published version.
Related
- Which projects use a NuGet package, and the build order
- Find internal NuGet packages nobody uses any more
- Switchyard for .NET: know what a package change touches
- All guides
Sources (Microsoft Learn): dotnet package list, Central Package Management, Package versioning and version ranges, PackageReference in project files.