How can I get the NuGet package version programmatically from a NuGet feed?(如何以编程方式从 NuGet 源获取 NuGet 包版本?)
问题描述
首先,在所有 NuGet 代码中,我试图找出要引用的代码.
First off, of all the NuGet code, I'm trying to figure out which one to reference.
主要问题是,给定一个 NuGet 包名称,是否有一种编程方式可以从 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 包版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何以编程方式从 NuGet 源获取 NuGet 包版本?


基础教程推荐
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01