Ejemplo n.º 1
0
        private async Task <ExitCode> ProcessPackagesAsync(
            IEnumerable <string> packageSpecifications,
            NuGetPackageConfiguration packageConfiguration,
            ILogger logger,
            CancellationToken cancellationToken)
        {
            var packager = new NuGetPackager(logger);

            foreach (string packageSpecification in packageSpecifications)
            {
                ExitCode packageResult =
                    await packager.CreatePackageAsync(
                        packageSpecification,
                        packageConfiguration,
                        cancellationToken : cancellationToken);

                if (!packageResult.IsSuccess)
                {
                    logger.WriteError($"Could not create NuGet package from specification '{packageSpecification}'");
                    return(packageResult);
                }
            }

            return(ExitCode.Success);
        }
Ejemplo n.º 2
0
        public async Task <ExitCode> ExecuteAsync(
            ILogger logger,
            IReadOnlyCollection <IVariable> buildVariables,
            CancellationToken cancellationToken)
        {
            bool enabled = buildVariables.GetBooleanByKey(WellKnownVariables.NuGetPackageEnabled, true);

            if (!enabled)
            {
                logger.WriteWarning(
                    $"NuGet Packer is disabled (build variable '{WellKnownVariables.NuGetPackageEnabled}' is set to false");
                return(ExitCode.Success);
            }

            _excludedNuSpecFiles =
                buildVariables.GetVariableValueOrDefault(
                    WellKnownVariables.NuGetPackageExcludesCommaSeparated,
                    string.Empty)
                .Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries)
                .SafeToReadOnlyCollection();

            _pathLookupSpecification = DefaultPaths.DefaultPathLookupSpecification;

            string packageDirectory = PackageDirectory();

            IVariable artifacts         = buildVariables.Require(WellKnownVariables.Artifacts).ThrowIfEmptyValue();
            string    packagesDirectory = Path.Combine(artifacts.Value, "packages");

            string vcsRootDir = buildVariables.Require(WellKnownVariables.SourceRoot).ThrowIfEmptyValue().Value;

            NuGetPackageConfiguration packageConfiguration =
                NuGetPackager.GetNuGetPackageConfiguration(logger, buildVariables, packagesDirectory, vcsRootDir);

            IReadOnlyCollection <string> packageSpecifications = GetPackageSpecifications(
                logger,
                vcsRootDir,
                packageDirectory);

            if (!packageSpecifications.Any())
            {
                logger.Write("Could not find any NuGet specifications to create NuGet packages from");
                return(ExitCode.Success);
            }

            logger.Write($"Found {packageSpecifications.Count} NuGet specifications to create NuGet packages from");

            ExitCode result =
                await ProcessPackagesAsync(packageSpecifications, packageConfiguration, logger, cancellationToken);

            return(result);
        }