Last active
November 10, 2017 02:17
-
-
Save joelverhagen/cd95871f2292a317edd4cf0ff5e87bec to your computer and use it in GitHub Desktop.
Latest version of a NuGet package in PowerShell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# See: https://docs.microsoft.com/en-us/nuget/api/service-index | |
$serviceIndex = Invoke-RestMethod "https://api.nuget.org/v3/index.json" | |
$searchUrl = $serviceIndex.resources ` | |
| ? { ($_ | Select -ExpandProperty "@type") -eq "SearchQueryService" } ` | |
| % { $_ | Select -ExpandProperty "@id" } ` | |
| Select-Object -First 1 | |
$packageId = "NuGet.Versioning" | |
$includePrerelease = $true | |
# See: https://docs.microsoft.com/en-us/nuget/api/search-query-service-resource#search-for-packages | |
$searchQueryUrl = "$($searchUrl)?q=packageid:$packageId&prerelease=$includePrerelease" | |
$searchResults = Invoke-RestMethod $searchQueryUrl | |
if ($searchResults.totalHits -lt 1) { | |
Write-Output "No results found for $packageId (include prerelease = $includePrerelease)." | |
exit | |
} | |
$latestVersion = $searchResults.data[0].version | |
Write-Output "The latest version of $packageId is $latestVersion." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The latest version of NuGet.Versioning is 4.4.0. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment