nugetazure-pipelinesnuget-packageproget

Is there a way to check if a nuget package is already on a ProGet Repo?


So, I've been working on an azure pipeline that is supposed to download a NuGet package and then upload it to a ProGet feet. But it should only upload the package if it doesn't yet exist on the feed to avoid redundancy. (If the package already exists on the feed, but the version is different, it should still be uploaded). Is there a way to check if a package already exists on a ProGet feed using nuget.exe or some other kind of NuGet tool?


Solution

  • You can use one of the several options here.

    The first one is to use nuget.exe, in particular, its list command. The following command will list all versions of the package available on the feed:

    nuget list <PackageName> -Source <ProgetFeedURL> -AllVersions
    

    where <PackageName> is obviously the [part of the] package name, and <ProgetFeedURL> is the feed URL. The output is a list of packages along with their versions you can easily parse to find out whether the version in question is already on the feed.

    The other approach could be to form a download URL for a package in ProGet and send a simple GET request to that URL. The URL is generally formed like this (note that your version of ProGet might form a different URL. You can verify that if you hover a mouse over the Download button in the browser):

    http(s)://<ProGetServer>/nuget/<ProGetFeed>/package/<PackageName>/<PackageVersion>
    

    In case this GET request results in 404, you can be sure there's no such version of that package on the feed.

    I suppose there must be some REST API of Proget to verify a similar stuff, but I haven't worked with that.