本文整理匯總了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);
}