Check if NuGet packages are publicly available

When creating solutions for a company, you often use an internal package feed.
There might come a time when you need to provide the source code to an external party or you want to make the solution open source.

If this has ever happened to you, you know one of the first things to validate if all dependencies (NuGet packages) are available to the public. Especially in large corporations it’s easy to use some platform packages used throughout the company but should not be shared with the public.

I recently had to so one of those exercises. And instead of manually searching for all packages on NuGet.org, I created a small PowerShell script to search for the packages and version in the feed.

# Path to the Directory.Packages.props file
$filePath = "C:\Projects\Internal\MySolution\Directory.Packages.props"

# Load the XML file
[xml]$xml = Get-Content $filePath

# Iterate through each PackageVersion element
foreach ($package in $xml.Project.ItemGroup.PackageVersion) {
    $packageName = $package.Include
    $packageVersion = $package.Version

    # Check if the package exists in NuGet
    $result = nuget list $packageName -Source https://api.nuget.org/v3/index.json

    if ($result -match $packageName) {
        Write-Host "Package '$packageName' (Version: $packageVersion) is available."
    } else {
        Write-Host "Package '$packageName' (Version: $packageVersion) is NOT available."
    }
}

By running this, you can see in the output if a package is or is not available for your external consumers. It’s not rocket science but has sure saved me hours of searching for this information manually.


Share