Пример #1
0
        private static void ConvertProject(Options options)
        {
            var conversionOptions = options.ConversionOptions;

            var convertedProjects = new List <Project>();

            ILogger logger = new ConsoleLogger("console", (s, l) => l >= LogLevel.Information, true);

            logger.LogWarning("csproj-to-2017 is deprecated and will be removed soon");
            logger.LogInformation("Consider migrating to Project2015To2017.Migrate2017.Tool (dotnet migrate-2017)");

            foreach (var file in options.Files)
            {
                var projects = new ProjectConverter(logger, Vs15TransformationSet.Instance, conversionOptions)
                               .Convert(file)
                               .Where(x => x != null)
                               .ToList();
                convertedProjects.AddRange(projects);
            }

            System.Console.Out.Flush();

            var analyzer = new Analyzer <LoggerReporter, LoggerReporterOptions>(new LoggerReporter(logger));

            foreach (var project in convertedProjects)
            {
                analyzer.Analyze(project);
            }

            if (options.DryRun)
            {
                return;
            }

            var doBackup = !options.NoBackup;

            var writer = new Writing.ProjectWriter(logger, x => x.Delete(), _ => { });

            foreach (var project in convertedProjects)
            {
                writer.Write(project, doBackup);
            }

            System.Console.Out.Flush();

            logger.LogInformation("### Performing 2nd pass to analyze converted projects...");

            conversionOptions.ProjectCache?.Purge();

            convertedProjects.Clear();

            foreach (var file in options.Files)
            {
                var projects = new ProjectConverter(logger, BasicReadTransformationSet.Instance, conversionOptions)
                               .Convert(file)
                               .Where(x => x != null)
                               .ToList();
                convertedProjects.AddRange(projects);
            }

            System.Console.Out.Flush();

            foreach (var project in convertedProjects)
            {
                analyzer.Analyze(project);
            }
        }