當前位置: 首頁>>代碼示例>>C#>>正文


C# ZipPackage.ToPackage方法代碼示例

本文整理匯總了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);
        }
開發者ID:Nemo157,項目名稱:DocNuget,代碼行數:54,代碼來源:NuGetPackageLoader.cs


注:本文中的NuGet.ZipPackage.ToPackage方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。