How can I list all local packages in the NuGet v3 API

In the context, I am creating an application that needs to download / unpack packages and their dependencies from arbitrary package sources (including the common gallery by default) and update these packages to the latest version upon request. There are no project.json files or similar files, they are all code driven. This is not a particularly difficult use case and does not require too much code in the v2 APIs.

However, in v3, I cannot figure out how to properly interact with the local package repository. For example, the FolderNuGetProject class, which I would think, lists all the packages on the disk in a specific place in FolderNuGetProject.GetInstalledPackagesAsync() just returns an empty enumerated . To make things more confusing, FolderNuGetProject.PackageExists() really returns if a package exists on disk, which means that GetInstalledPackagesAsync() and PackageExists() seem to be inconsistent.

No other NuGetProject derivatives are associated with the file system. Is there any other way to list packages that were installed in a specific folder? If I need to create my own NuGetProject (and I hope this does not happen), are there any methods that will help to parse the names of folders created by NuGet into package identifiers and their versions, or is this the only reliable way to get the identifier and version to open nuspec (and are there any methods for searching there)?

One interpretation of why this does not work, as I expect it, is that NuGetProject.GetInstalledPackagesAsync () is not really intended to install installed packages (i.e. those that were downloaded and unpacked), but rather those which were announced in any project system. For example, the BuildIntegratedNuGetProject class BuildIntegratedNuGetProject return package references for packages in project.json, regardless of their status on disk. This also explains why FolderNuGetProject simply returns an empty enumeration because there are no "declared" packages if you just look at the local repository.

TL DR: What is the best way to bypass the local package repository and get the packages and versions that are there?

(this was also issue # 2664 in the NuGet GitHub project, but was moved here on request)

+5
source share
2 answers

Introduction

I have the same question and I looked at your post on GitHub , Google and here. I am trying to find many local packages. I found some solutions, but I do not know if this is the best for this. I posted a question about local packages because I can list all local packages, but I cannot have the AssemblyReferences (dll) property.

Code example

 var rootPath = @"pathWhereNuGetPackagesAre"; var logger = new Logger(); List<Lazy<INuGetResourceProvider>> providers = new List<Lazy<INuGetResourceProvider>>(); providers.AddRange(Repository.Provider.GetCoreV3()); FindLocalPackagesResourceV2 findLocalPackagev2 = new FindLocalPackagesResourceV2(rootPath); var packageFound = findLocalPackagev2.GetPackages(logger, CancellationToken.None).FirstOrDefault(); //found, but missing a lot of informations... var supportedFramework = new[] { ".NETFramework,Version=v4.6" }; var searchFilter = new SearchFilter(true) { SupportedFrameworks = supportedFramework, IncludeDelisted = false }; // The trick here is to put the local nuget path, not using the URL : https://api.nuget.org/v3/index.json PackageSource localSource = new PackageSource(rootPath); SourceRepository localRepository = new SourceRepository(localSource, providers); PackageSearchResource searchLocalResource = await localRepository .GetResourceAsync<PackageSearchResource>(); var packageFound3 = await searchLocalResource .SearchAsync("Newtonsoft.Json", searchFilter, 0, 10, logger, CancellationToken.None); var thePackage = packageFound3.FirstOrDefault(); // found but missing the assemblies property public class Logger : ILogger { private List<string> logs = new List<string>(); public void LogDebug(string data) { logs.Add(data); } public void LogVerbose(string data) { logs.Add(data); } public void LogInformation(string data) { logs.Add(data); } public void LogMinimal(string data) { logs.Add(data); } public void LogWarning(string data) { logs.Add(data); } public void LogError(string data) { logs.Add(data); } public void LogInformationSummary(string data) { logs.Add(data); } public void LogErrorSummary(string data) { logs.Add(data); } } 

Hope this helps!

+1
source

In Visual Studio, open the package manager console.

enter image description here

The following command is used in the list of local (installed) packages.

 Get-Package 

You can list all available packages in the feed with the following command

 Get-Package -ListAvailable 

If these commands do not work, check the "Package Manager Settings" β†’ "Package Source" checkbox and configure the nougat feed correctly. (If you do not see the URL of your channel, you should add your channel there.) For more information: Consume the nuget package from VS

You can also check the nuget channel configuration from this file C: \ Users {{user}} \ AppData \ Roaming \ NuGet \ NuGet.config for more information on the nuget configuration file: nuget configuration file

In addition, local nuget packages must be stored in this path C:. \ Users {{user}} \ NuGet packages

0
source

All Articles