Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if nuget package exists using command line

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?

Scenario:

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.

like image 704
Liero Avatar asked Feb 25 '16 15:02

Liero


1 Answers

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:

check_nupkg.bat

@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

like image 103
kayleeFrye_onDeck Avatar answered Sep 19 '22 01:09

kayleeFrye_onDeck