如何从NuGet提要中以编程方式获取NuGet软件包的版本? [英] How can I get the NuGet package version programmatically from a NuGet feed?

查看:126
本文介绍了如何从NuGet提要中以编程方式获取NuGet软件包的版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,在所有NuGet代码中,我试图找出要引用的代码。

First off, of all the NuGet code, I'm trying to figure out which one to reference.

主要问题是,给定NuGet包名称 em>,是否有一种编程方式可以从NuGet提要中检索版本以及常规版本的最新版本?

The main question is, given a NuGet package name, is there a programmatic way to retrieve the versions from the NuGet feed and also the latest version for general consumption?

例如,给定一个软件包名称ILMerge,那将是不错的选择以获得2.13.307的最新软件包版本。

For example, given a package name of ILMerge, it would be nice to get the latest package version of 2.13.307.

// Pseudo code, makes a lot of assumptions about NuGet programmatic interfaces
PackageRef currentVersion = nugetlib.getpackageinfo(args[0]);
Console.WriteLine("Package Id: '{0}':", pkg.Id);
Console.WriteLine("  Current version: {0}", pkg.Version);
Console.WriteLine("  Available versions: {0}", String.Join(",",pkg.Versions.Select(_=>_)));


推荐答案

使用 NuGet核心程序包

string packageID = "ILMerge";

// Connect to the official package repository
IPackageRepository repo = PackageRepositoryFactory.Default.CreateRepository("https://packages.nuget.org/api/v2");
var version =repo.FindPackagesById(packageID).Max(p=>p.Version);

参考: 以编程方式播放软件包!

这篇关于如何从NuGet提要中以编程方式获取NuGet软件包的版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆