コード例 #1
0
        static int Main(string[] args)
        {
            /*
             * args = new [] {"/config", "solutions.txt"};
             *
             * Console.WriteLine("#################");
             * args.ToList().ForEach(Console.WriteLine);
             * Console.WriteLine("#################");
             */

            var nonstop       = false;
            var consolidate   = false;
            var outputSlnPath = "merged.sln";
            var fixDupeGuids  = false;
            var solutionNames = new List <string>();

            for (var i = 0; i < args.Length; i++)
            {
                switch (args[i].ToLower())
                {
                case "/?":
                case "/help":
                case "/h":
                    break;

                case "/nonstop":
                    nonstop = true;
                    break;

                case "/copy":    //used to actually copy solutions into a single directory
                    consolidate = true;
                    break;

                case "/out":
                    outputSlnPath = args[i + 1];
                    i++;
                    break;

                case "/fix":
                    fixDupeGuids = true;
                    break;

                case "/config":
                    solutionNames.AddRange(File.ReadAllLines(args[i + 1]).Where(fn => !string.IsNullOrEmpty(fn)));
                    i++;
                    break;

                default:
                    solutionNames.AddRange(args.Skip(i));
                    i = args.Length;
                    break;
                }
            }

            if (solutionNames.Count == 0)
            {
                OutputHelp();
                return(-1);
            }

            if (fixDupeGuids)
            {
                Console.WriteLine("Program is going to modify lots of various .sln and .proj files");
                Console.WriteLine("Please make sure that you have a backup copy");
                Console.WriteLine("Press ENTER to continue or anything else to stop ...");
                var key = Console.ReadKey();
                if (key.Key != ConsoleKey.Enter)
                {
                    return(-1);
                }
            }

            string warnings;
            string errors = "";

            if (fixDupeGuids)
            {
                ProjectReferenceFixer.FixAllSolutions(solutionNames.Select(SolutionInfo.Parse).ToArray(), out errors);
            }

            outputSlnPath = Path.GetFullPath(outputSlnPath);

            SolutionInfo aggregateSolution;

            if (!consolidate)
            {
                aggregateSolution = SolutionInfo.MergeSolutions(
                    Path.GetFileNameWithoutExtension(outputSlnPath),
                    Path.GetDirectoryName(outputSlnPath),
                    out warnings,
                    solutionNames.Select(SolutionInfo.Parse).ToArray());
            }
            else
            {
                //additional functionality - Cameron Block
                aggregateSolution = SolutionInfo.ConsolidateSolutions(
                    Path.GetFileNameWithoutExtension(outputSlnPath),
                    Path.GetDirectoryName(outputSlnPath),
                    out warnings,
                    solutionNames.Select(SolutionInfo.Parse).ToArray());
            }

            aggregateSolution.Save();

            Console.WriteLine("Merged solution: {0}", outputSlnPath);

            if (!string.IsNullOrWhiteSpace(errors))
            {
                Console.WriteLine("ERRORS found:");
                Console.Write(errors);
                Console.WriteLine("Press a key to exit...");
                Console.ReadKey();
                return(-3);
            }

            if (!string.IsNullOrWhiteSpace(warnings))
            {
                Console.WriteLine("WARNINGS found:");
                Console.Write(warnings);
                Console.WriteLine("You might want to try running SolutionMerger with /fix parameter. Execute SolutionMerger.exe /help for more details.");
                if (!nonstop)
                {
                    Console.WriteLine("Press a key to exit...");
                    Console.ReadKey();
                }
                return(-2);
            }

            return(0);
        }