本文整理汇总了C#中NuGet.ZipPackage.ToPackage方法的典型用法代码示例。如果您正苦于以下问题:C# ZipPackage.ToPackage方法的具体用法?C# ZipPackage.ToPackage怎么用?C# ZipPackage.ToPackage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NuGet.ZipPackage
的用法示例。
在下文中一共展示了ZipPackage.ToPackage方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadAsync
public async Task<Package> LoadAsync(string id, string version) {
var logger = _loggerFactory.CreateLogger<NuGetPackageLoader>();
var sourceProvider = new PackageSourceProvider(
NullSettings.Instance,
new[] {
new PackageSource(NuGetConstants.DefaultFeedUrl),
new PackageSource("https://www.myget.org/F/aspnetvnext/api/v2"),
});
var feeds = sourceProvider
.LoadPackageSources()
.Select(source =>
PackageSourceUtils.CreatePackageFeed(
source,
noCache: false,
ignoreFailedSources: false,
reports: logger.CreateReports()))
.Where(f => f != null);
logger.LogInformation($"Looking up {id} v{version} from nuget");
var packages = (await Task.WhenAll(feeds.Select(feed => feed.FindPackagesByIdAsync(id))))
.SelectMany(_ => _)
.OrderByDescending(p => p.Version);
var package = version == null
? packages.FirstOrDefault()
: packages.FirstOrDefault(p => p.Version == new SemanticVersion(version));
if (package == null) {
logger.LogError($"Unable to locate {id} v{version}");
return null;
}
logger.LogInformation($"Found version {package.Version} of {package.Id}");
var pkgStreams = await Task.WhenAll(feeds.Select(feed => {
try {
return feed.OpenNupkgStreamAsync(package);
} catch {
return null;
}
}));
var pkgStream = pkgStreams.FirstOrDefault(s => s != null);
var zipPackage = new ZipPackage(pkgStream);
if (zipPackage == null) {
logger.LogError($"Unable to open package stream for {id} v{version}");
return null;
}
return zipPackage.ToPackage(packages.Select(p => p.Version.ToString()).ToList(), logger);
}