使用 Nuget.VisualStudio 如何从存储库中获取包列表

Using Nuget.VisualStudio how would I get a list of packages from a repository

使用 Nuget.VisualStudio Nuget 包时,如何获取包列表以允许用户选择一个进行安装?

我正在迁移一个针对 Visual Studio 2013 Nuget API 构建的 vsix 项目,以将 API 用于 Visual Studio 2017。我正在使用此 documentation 设置有以下警告的 Nuget 服务。

Do not use any other types besides the public interfaces in your code, and do not reference any other Nuget assemblies, including NuGet.Core.dll.

Visual Studio 2013 vsix 项目使用 Nuget.Core 获取可以安装的软件包列表。不幸的是,当我添加 Nuget.Core 时,会出现大量名称空间冲突。这是我们从 Nuget.Core 包中使用的代码,我需要在新的 Nuget API.

中找到等效的代码
 IPackageRepository repo = PackageRepositoryFactory.Default.CreateRepository("http://ourfeed.net/nuget");
 List<IPackage> packages = repo.GetPackages().Where(p => p.Tags.Contains(tag))
           .OrderByDescending(p => p.Version)
           .Take(packagesPerTag).ToList();;

Using Nuget.VisualStudio how would I get a list of packages from a repository

根据NuGet/NuGet2:

NuGet2

This is the home of nuget.core and all the repos from codeplex. This repository is for Version 2 of NuGet. Version 3 of the Nuget client library has moved to Nuget.Client. See the NuGet API v3 documentation for more information.

有关 NuGet 客户端 SDK 的更多信息,请参阅 NuGet API v3 文档:

https://docs.microsoft.com/en-us/nuget/reference/nuget-client-sdk

下面是一些更有用的博文:

查看 了解更多详情。

希望对您有所帮助。