英文:
How can i get the release notes of a NuGet package with the official SDK in C#
问题
我需要获取存储在元数据中的发布说明。这段代码似乎能够读取元数据,但我不知道如何获取发布说明。
using NuGet.Common;
using NuGet.Protocol;
using NuGet.Protocol.Core.Types;
using NuGet.Versioning;
ILogger logger = NullLogger.Instance;
CancellationToken cancellationToken = CancellationToken.None;
SourceCacheContext cache = new SourceCacheContext();
SourceRepository repository = Repository.Factory.GetCoreV3("https://api.nuget.org/v3/index.json");
PackageMetadataResource resource = await repository.GetResourceAsync<PackageMetadataResource>();
IEnumerable<IPackageSearchMetadata> packages = await resource.GetMetadataAsync(
"Flexygo",
includePrerelease: true,
includeUnlisted: false,
cache,
logger,
cancellationToken);
我正在尝试只使用官方 SDK 获取包含发布说明的字符串。
英文:
I need to get the Release Notes stored in the metadata. This code seems to be able to read the metadata, however i dont know how to get to the release notes.
using NuGet.Common;
using NuGet.Protocol;
using NuGet.Protocol.Core.Types;
using NuGet.Versioning;
ILogger logger = NullLogger.Instance;
CancellationToken cancellationToken = CancellationToken.None;
SourceCacheContext cache = new SourceCacheContext();
SourceRepository repository = Repository.Factory.GetCoreV3("https://api.nuget.org/v3/index.json");
PackageMetadataResource resource = await repository.GetResourceAsync<PackageMetadataResource>();
IEnumerable<IPackageSearchMetadata> packages = await resource.GetMetadataAsync(
"Flexygo",
includePrerelease: true,
includeUnlisted: false,
cache,
logger,
cancellationToken);
i am trying to get a String with the release notes using only the official SDK
答案1
得分: 2
你可以使用库NuGet.Client
来实现上述操作。通过以下代码,可以使用NuGet包管理器控制台安装以下库:
Install-Package NuGet.Client
如果不想这样做,你也可以根据以下方式更改你自己的代码以打印提取的所有信息:
using NuGet.Common;
using NuGet.Protocol;
using NuGet.Protocol.Core.Types;
using System.Reflection;
class Program
{
static async Task Main()
{
ILogger logger = NullLogger.Instance;
CancellationToken cancellationToken = CancellationToken.None;
SourceCacheContext cache = new SourceCacheContext();
SourceRepository repository = Repository.Factory.GetCoreV3("https://api.nuget.org/v3/index.json");
PackageMetadataResource resource = await repository.GetResourceAsync<PackageMetadataResource>();
IEnumerable<IPackageSearchMetadata> packages = await resource.GetMetadataAsync(
"Flexygo",
includePrerelease: true,
includeUnlisted: false,
cache,
logger,
cancellationToken);
foreach (var package in packages)
{
var packageMetadata = await resource.GetMetadataAsync(package.Identity, cache, logger, cancellationToken);
var v = await packageMetadata.GetDeprecationMetadataAsync();
Console.WriteLine("------------------------------------------------------------------");
Console.WriteLine("Package Metadata: " + packageMetadata.Title.ToString());
Type t = packageMetadata.GetType();
PropertyInfo[] pi = t.GetProperties();
foreach (PropertyInfo p in pi)
{
System.Console.WriteLine(p.Name + " : " + p.GetValue(packageMetadata));
}
Console.WriteLine("------------------------------------------------------------------");
}
}
}
英文:
You can achieve the above using the Library NuGet.Client
. Install the following library using your Nuget package manager console via the below code :
Install-Package NuGet.Client
If not you can alter your own code as per below to print all information extracted :
using NuGet.Common;
using NuGet.Protocol;
using NuGet.Protocol.Core.Types;
using System.Reflection;
class Program
{
static async Task Main()
{
ILogger logger = NullLogger.Instance;
CancellationToken cancellationToken = CancellationToken.None;
SourceCacheContext cache = new SourceCacheContext();
SourceRepository repository = Repository.Factory.GetCoreV3("https://api.nuget.org/v3/index.json");
PackageMetadataResource resource = await repository.GetResourceAsync<PackageMetadataResource>();
IEnumerable<IPackageSearchMetadata> packages = await resource.GetMetadataAsync(
"Flexygo",
includePrerelease: true,
includeUnlisted: false,
cache,
logger,
cancellationToken);
foreach (var package in packages)
{
var packageMetadata = await resource.GetMetadataAsync(package.Identity, cache, logger, cancellationToken);
var v = await packageMetadata.GetDeprecationMetadataAsync();
Console.WriteLine("------------------------------------------------------------------");
Console.WriteLine("Package Metadata: " + packageMetadata.Title.ToString());
Type t = packageMetadata.GetType();
PropertyInfo[] pi = t.GetProperties();
foreach (PropertyInfo p in pi)
{
System.Console.WriteLine(p.Name + " : " + p.GetValue(packageMetadata));
}
Console.WriteLine("------------------------------------------------------------------");
}
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论