简体   繁体   English

从 URL 指定的远程存储库中获取 NuGet package 版本,而不使用 Z20055252BAD767BE760C329

[英]Get NuGet package version from remote repository specified by URL without using NuGet.Core

NuGet.Core has been deprecated, I am struggling to find out an API to get NuGet package version from remote repository specified by URL. NuGet.Core has been deprecated, I am struggling to find out an API to get NuGet package version from remote repository specified by URL. Using IPackageRepository was quite straight forward but I am not getting any way how to do it without using NuGet.Core?使用 IPackageRepository 非常简单,但如果不使用 NuGet.Core,我没有任何方法可以做到这一点?

Edit: FactoryExtensionsV3.GetCoreV3 probably refers to "NuGet version 3", not NuGet's v3 HTTP API.编辑:FactoryExtensionsV3.GetCoreV3 可能指的是“NuGet 版本 3”,而不是 NuGet 的 v3 HTTP API。 So, this code works for local file feeds as well as both V2 and V3 HTTP feeds.因此,此代码适用于本地文件提要以及 V2 和 V3 HTTP 提要。 Just change the URL passed to PackageSource.只需更改传递给 PackageSource 的 URL 即可。

static async Task Main(string[] args)
{
    var packageSource = new PackageSource("https://api.nuget.org/v3/index.json");
    var sourceRepository = new SourceRepository(packageSource, FactoryExtensionsV3.GetCoreV3(null));

    var metadata = await sourceRepository.GetResourceAsync<MetadataResource>();
    var cacheContext = new SourceCacheContext();
    var versions = await metadata.GetVersions("newtonsoft.json", cacheContext, NullLogger.Instance, CancellationToken.None);

    foreach (var version in versions)
    {
        Console.WriteLine("Found version " + version.ToNormalizedString());
    }
}

I've made a package to make it easier to interact with NuGet V3 servers: https://github.com/loic-sharma/BaGet/tree/master/src/BaGet.Protocol#list-package-versions我制作了一个 package 以使其更容易与 NuGet V3 服务器交互: https://github.com/loic-package/-sharma/Protocol#list-package/-sharma/Protocol#list-package/-sharma/

NuGetClient client = new NuGetClient("https://api.nuget.org/v3/index.json");

IReadOnlyList<NuGetVersion>> versions = await client.ListPackageVersionsAsync("Newtonsoft.Json");

foreach (NuGetVersion version in versions)
{
    Console.WriteLine($"Found version: {version}");
}

Please let me know if you have any feedback or suggestions: :)如果您有任何反馈或建议,请告诉我::)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM