我有一个nuget软件包的名称和版本,需要提取每个软件包的许可证文本。
我通过阅读几个博客设法读取了许可URL,但是整个文档确实很少。由于不赞成使用许可证网址,因此我必须读出许可证信息本身。但是用我采用的方法似乎是不可能的:
public static async Task<IPackageSearchMetadata> GetNugetPackageMetaData(string name, string version)
{
//workaround for beta/alpha
if (version.Contains("-"))
{
int dashIndex = version.IndexOf("-");
version = version.Substring(0, dashIndex);
}
int[] versions = Array.ConvertAll(version.Split("."), int.Parse);
NuGetVersion nuGetVersion = new NuGetVersion(versions[0], versions[1], versions[2]);
PackageIdentity packageIdentity = new PackageIdentity(name, nuGetVersion);
List<Lazy<INuGetResourceProvider>> providers = new List<Lazy<INuGetResourceProvider>>();
providers.AddRange(Repository.Provider.GetCoreV3()); // Add v3 API support
PackageSource packageSource = new PackageSource("https://api.nuget.org/v3/index.json");
SourceRepository sourceRepository = new SourceRepository(packageSource, providers);
PackageMetadataResource packageMetadataResource = await sourceRepository.GetResourceAsync<PackageMetadataResource>();
IPackageSearchMetadata searchMetadata =
await packageMetadataResource.GetMetadataAsync(packageIdentity, new SourceCacheContext(), NullLogger.Instance, CancellationToken.None);
return searchMetadata;
}
是否还可以使用nugetv3甚至更好的整个nuspec文件获取许可证文本?