コード例 #1
0
        private void ExecuteImpl()
        {
            bool isRelease;

            if (StringComparer.OrdinalIgnoreCase.Equals(VersionKind, "release"))
            {
                isRelease = true;
            }
            else if (StringComparer.OrdinalIgnoreCase.Equals(VersionKind, "prerelease"))
            {
                isRelease = false;
            }
            else
            {
                Log.LogError($"Invalid value for task argument {nameof(VersionKind)}: '{VersionKind}'. Specify 'release' or 'prerelease'.");
                return;
            }

            try
            {
                NuGetVersionUpdater.Run(Packages, OutputDirectory, isRelease);
            }
            catch (AggregateException e)
            {
                foreach (var inner in e.InnerExceptions)
                {
                    Log.LogErrorFromException(inner);
                }
            }
            catch (Exception e)
            {
                Log.LogErrorFromException(e);
            }
        }
コード例 #2
0
        private void ExecuteImpl()
        {
            VersionTranslation translation;

            if (string.IsNullOrEmpty(VersionKind))
            {
                translation = VersionTranslation.None;
            }
            else if (StringComparer.OrdinalIgnoreCase.Equals(VersionKind, "release"))
            {
                translation = VersionTranslation.Release;
            }
            else if (StringComparer.OrdinalIgnoreCase.Equals(VersionKind, "prerelease"))
            {
                translation = VersionTranslation.PreRelease;
            }
            else
            {
                Log.LogError($"Invalid value for task argument {nameof(VersionKind)}: '{VersionKind}'. Specify 'release' or 'prerelease' or leave empty.");
                return;
            }

            var preReleaseDependencies = new List <string>();

            try
            {
                NuGetVersionUpdater.Run(Packages, OutputDirectory, translation, ExactVersions, allowPreReleaseDependency: (packageId, dependencyId, dependencyVersion) =>
                {
                    if (AllowPreReleaseDependencies)
                    {
                        Log.LogMessage(MessageImportance.High, $"Package '{packageId}' depends on a pre-release package '{dependencyId}, {dependencyVersion}'");
                        preReleaseDependencies.Add($"{dependencyId}, {dependencyVersion}");
                        return(true);
                    }

                    return(false);
                });

                if (translation == VersionTranslation.Release)
                {
                    File.WriteAllLines(Path.Combine(OutputDirectory, "PreReleaseDependencies.txt"), preReleaseDependencies.Distinct());
                }
            }
            catch (AggregateException e)
            {
                foreach (var inner in e.InnerExceptions)
                {
                    Log.LogErrorFromException(inner);
                }
            }
            catch (Exception e)
            {
                Log.LogErrorFromException(e);
            }
        }
コード例 #3
0
        private static int Main(string[] args)
        {
            var    operation    = Operation.None;
            var    packages     = new List <string>();
            string outDirectory = null;

            try
            {
                int i = 0;
                while (i < args.Length)
                {
                    var arg = args[i++];

                    string ReadValue() => (i < args.Length) ? args[i++] : throw new InvalidDataException($"Missing value for option {arg}");

                    switch (arg)
                    {
                    case "/rel":
                    case "/release":
                        operation = Operation.Release;
                        break;

                    case "/prerel":
                    case "/prerelease":
                        operation = Operation.PreRelease;
                        break;

                    case "/out":
                        outDirectory = ReadValue();
                        break;

                    default:
                        if (arg.StartsWith("/", StringComparison.Ordinal))
                        {
                            throw new InvalidDataException($"Unrecognized option: '{arg}'");
                        }

                        if (Directory.Exists(arg))
                        {
                            foreach (var file in Directory.GetFiles(arg))
                            {
                                if (file.EndsWith(".nupkg"))
                                {
                                    packages.Add(file);
                                }
                            }
                        }
                        else
                        {
                            packages.Add(arg);
                        }

                        break;
                    }
                }

                switch (operation)
                {
                case Operation.Release:
                case Operation.PreRelease:
                    if (packages.Count == 0)
                    {
                        throw new InvalidDataException($"Must specify at least one package");
                    }

                    break;

                default:
                    throw new InvalidDataException($"Operation not specified");
                }
            }
            catch (InvalidDataException e)
            {
                Console.Error.WriteLine("Usage: NuGetRepack <operation> <options> <packages>");
                Console.Error.WriteLine();
                Console.Error.WriteLine("Operation:");
                Console.Error.WriteLine("  /rel[ease]           Strip pre-release version suffix from versions of specified package(s).");
                Console.Error.WriteLine("  /prerel[ease]        Strip per-build version suffix from versions of specified package(s).");
                Console.Error.WriteLine();
                Console.Error.WriteLine("Options:");
                Console.Error.WriteLine("  /out <path>          Optional path to an output directory. Validation is performed if not specified.");
                Console.Error.WriteLine();
                Console.Error.WriteLine("<packages>             Paths to .nupkg files.");
                Console.Error.WriteLine(e.Message);
                return(ExitCodeInvalidArgument);
            }

            try
            {
                switch (operation)
                {
                case Operation.Release:
                    NuGetVersionUpdater.Run(packages, outDirectory, release: true);
                    break;

                case Operation.PreRelease:
                    NuGetVersionUpdater.Run(packages, outDirectory, release: false);
                    break;

                default:
                    throw new InvalidDataException($"Operation not specified");
                }
            }
            catch (AggregateException e)
            {
                foreach (var inner in e.InnerExceptions)
                {
                    Console.Error.WriteLine(inner.Message);
                }

                return(ExitCodeMultipleErrors);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.Message);
                return(ExitCodeError);
            }

            return(ExitCodeSuccess);
        }