How can I check if nuget package with specific version exists in a specified package source (nuget server) using powershell or commandline outside visual studio?
I have private NuGet server where I want to push my own packages. I have automated creation of the packages during TFS build. What I miss is check, if the package was previously uploaded and published to the NuGet Server.
You can call this CMD script from PowerShell easy enough, with examples below it. You can just go by $LastExitCode
to determine how to proceed, with 0
meaning you can publish:
@echo off
SetLocal EnableDelayedExpansion EnableExtensions
pushd "%~dp0"
set "pkg_name=%~1"
set "pkg_version=%~2"
call nuget list %pkg_name% -AllVersions -Prerelease|findstr /i /r /c:"^%pkg_name% %pkg_version%$" -N>nul 2>&1
if not "%errorlevel%"=="0" (
echo This package can be published
exit /b 0
) else (
echo This package has already been published.
exit /b 1
)
C:\stuff>.\check_nupkg.bat "lolspeak" "1.0.0"
This package has already been published.
C:\stuff>check_nupkg.bat "lolspeak" "11.0.0"
This package can be published
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With