Пример #1
0
        private ProjectMigrationReport MigrateProject(MigrationSettings migrationSettings)
        {
            var migrationRuleInputs = ComputeMigrationRuleInputs(migrationSettings);
            var projectName         = migrationRuleInputs.DefaultProjectContext.GetProjectName();

            try
            {
                if (IsMigrated(migrationSettings, migrationRuleInputs))
                {
                    MigrationTrace.Instance.WriteLine($"{nameof(ProjectMigrator)}: Skip migrating {migrationSettings.ProjectDirectory}, it is already migrated.");
                    return(new ProjectMigrationReport(migrationSettings.ProjectDirectory, projectName, skipped: true));
                }

                VerifyInputs(migrationRuleInputs, migrationSettings);

                SetupOutputDirectory(migrationSettings.ProjectDirectory, migrationSettings.OutputDirectory);

                _ruleSet.Apply(migrationSettings, migrationRuleInputs);
            }
            catch (MigrationException exc)
            {
                var error = new List <MigrationError>
                {
                    exc.Error
                };

                return(new ProjectMigrationReport(migrationSettings.ProjectDirectory, projectName, error, null));
            }

            var outputProject = Path.Combine(migrationSettings.OutputDirectory, projectName + ".csproj");

            return(new ProjectMigrationReport(migrationSettings.ProjectDirectory, projectName, outputProject, null));
        }
Пример #2
0
        private ProjectMigrationReport MigrateProject(MigrationSettings migrationSettings)
        {
            var migrationRuleInputs = ComputeMigrationRuleInputs(migrationSettings);
            var projectName         = migrationRuleInputs.DefaultProjectContext.GetProjectName();

            try
            {
                if (IsMigrated(migrationSettings, migrationRuleInputs))
                {
                    MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.SkipMigrationAlreadyMigrated, nameof(ProjectMigrator), migrationSettings.ProjectDirectory));
                    return(new ProjectMigrationReport(migrationSettings.ProjectDirectory, projectName, skipped: true));
                }

                VerifyInputs(migrationRuleInputs, migrationSettings);

                SetupOutputDirectory(migrationSettings.ProjectDirectory, migrationSettings.OutputDirectory);

                _ruleSet.Apply(migrationSettings, migrationRuleInputs);
            }
            catch (MigrationException exc)
            {
                var error = new List <MigrationError>
                {
                    exc.Error
                };

                return(new ProjectMigrationReport(migrationSettings.ProjectDirectory, projectName, error, null));
            }

            List <string> csprojDependencies = null;

            if (migrationRuleInputs.ProjectXproj != null)
            {
                var projectDependencyFinder = new ProjectDependencyFinder();
                var dependencies            = projectDependencyFinder.ResolveXProjProjectDependencies(
                    migrationRuleInputs.ProjectXproj);

                if (dependencies.Any())
                {
                    csprojDependencies = dependencies
                                         .SelectMany(r => r.Includes().Select(p => PathUtility.GetPathWithDirectorySeparator(p)))
                                         .ToList();
                }
                else
                {
                    csprojDependencies = new List <string>();
                }
            }

            var outputProject = Path.Combine(migrationSettings.OutputDirectory, projectName + ".csproj");

            return(new ProjectMigrationReport(
                       migrationSettings.ProjectDirectory,
                       projectName,
                       outputProject,
                       null,
                       null,
                       csprojDependencies));
        }
Пример #3
0
        public MigrationReport Migrate(MigrationSettings rootSettings, bool skipProjectReferences = false)
        {
            if (rootSettings == null)
            {
                throw new ArgumentNullException();
            }

            // Try to read the project dependencies, ignore an unresolved exception for now
            MigrationRuleInputs             rootInputs          = ComputeMigrationRuleInputs(rootSettings);
            IEnumerable <ProjectDependency> projectDependencies = null;

            var tempMSBuildProjectTemplate = rootSettings.CloneMSBuildProjectTemplate();

            try
            {
                // Verify up front so we can prefer these errors over an unresolved project dependency
                VerifyInputs(rootInputs, rootSettings);

                projectDependencies = ResolveTransitiveClosureProjectDependencies(
                    rootSettings.ProjectDirectory,
                    rootSettings.ProjectXProjFilePath);
            }
            catch (MigrationException e)
            {
                return(new MigrationReport(
                           new List <ProjectMigrationReport>
                {
                    new ProjectMigrationReport(
                        rootSettings.ProjectDirectory,
                        rootInputs?.DefaultProjectContext.GetProjectName(),
                        new List <MigrationError> {
                        e.Error
                    },
                        null)
                }));
            }

            var projectMigrationReports = new List <ProjectMigrationReport>();

            projectMigrationReports.Add(MigrateProject(rootSettings));

            if (skipProjectReferences)
            {
                return(new MigrationReport(projectMigrationReports));
            }

            foreach (var project in projectDependencies)
            {
                var projectDir = Path.GetDirectoryName(project.ProjectFilePath);
                var settings   = new MigrationSettings(projectDir,
                                                       projectDir,
                                                       rootSettings.SdkPackageVersion,
                                                       tempMSBuildProjectTemplate);
                MigrateProject(settings);
                projectMigrationReports.Add(MigrateProject(settings));
            }

            return(new MigrationReport(projectMigrationReports));
        }
Пример #4
0
 public void Apply(MigrationSettings migrationSettings, MigrationRuleInputs migrationRuleInputs)
 {
     foreach (var rule in Rules)
     {
         MigrationTrace.Instance.WriteLine($"{nameof(DefaultMigrationRuleSet)}: Executing migration rule {rule.GetType().Name}");
         rule.Apply(migrationSettings, migrationRuleInputs);
     }
 }
Пример #5
0
        public bool IsMigrated(MigrationSettings migrationSettings, MigrationRuleInputs migrationRuleInputs)
        {
            var outputName = migrationRuleInputs.DefaultProjectContext.GetProjectName();

            var outputProject = Path.Combine(migrationSettings.OutputDirectory, outputName + ".csproj");

            return(File.Exists(outputProject));
        }
Пример #6
0
 private void VerifyInputs(
     MigrationRuleInputs migrationRuleInputs,
     MigrationSettings migrationSettings,
     out List <string> warningMessages
     )
 {
     VerifyProject(migrationRuleInputs.ProjectContexts, migrationSettings.ProjectDirectory, out warningMessages);
 }
Пример #7
0
 public void Apply(MigrationSettings migrationSettings, MigrationRuleInputs migrationRuleInputs)
 {
     foreach (var rule in Rules)
     {
         MigrationTrace.Instance.WriteLine(string.Format(LocalizableStrings.ExecutingMigrationRule, nameof(DefaultMigrationRuleSet), rule.GetType().Name));
         rule.Apply(migrationSettings, migrationRuleInputs);
     }
 }
Пример #8
0
        public bool IsMigrated(MigrationSettings migrationSettings, MigrationRuleInputs migrationRuleInputs)
        {
            var outputName = Path.GetFileNameWithoutExtension(
                migrationRuleInputs.DefaultProjectContext.GetOutputPaths("_").CompilationFiles.Assembly);

            var outputProject = Path.Combine(migrationSettings.OutputDirectory, outputName + ".csproj");

            return(File.Exists(outputProject));
        }
Пример #9
0
        public void Migrate(MigrationSettings migrationSettings)
        {
            var migrationRuleInputs = ComputeMigrationRuleInputs(migrationSettings);

            VerifyInputs(migrationRuleInputs, migrationSettings);

            SetupOutputDirectory(migrationSettings.ProjectDirectory, migrationSettings.OutputDirectory);

            _ruleSet.Apply(migrationSettings, migrationRuleInputs);
        }
Пример #10
0
        private void DeleteProjectJsons(MigrationSettings rootsettings, IEnumerable <ProjectDependency> projectDependencies)
        {
            try
            {
                File.Delete(Path.Combine(rootsettings.ProjectDirectory, "project.json"));
            } catch {}

            foreach (var projectDependency in projectDependencies)
            {
                try
                {
                    File.Delete(projectDependency.ProjectFilePath);
                } catch { }
            }
        }
Пример #11
0
        private MigrationRuleInputs ComputeMigrationRuleInputs(MigrationSettings migrationSettings)
        {
            var projectContexts = ProjectContext.CreateContextForEachFramework(migrationSettings.ProjectDirectory);

            var templateMSBuildProject = migrationSettings.MSBuildProjectTemplate;

            if (templateMSBuildProject == null)
            {
                throw new Exception("Expected non-null MSBuildProjectTemplate in MigrationSettings");
            }

            var propertyGroup = templateMSBuildProject.AddPropertyGroup();
            var itemGroup     = templateMSBuildProject.AddItemGroup();

            return(new MigrationRuleInputs(projectContexts, templateMSBuildProject, itemGroup, propertyGroup));
        }
Пример #12
0
        private void MigrateProject(MigrationSettings migrationSettings)
        {
            var migrationRuleInputs = ComputeMigrationRuleInputs(migrationSettings);

            if (IsMigrated(migrationSettings, migrationRuleInputs))
            {
                // TODO : Adding user-visible logging
                MigrationTrace.Instance.WriteLine($"{nameof(ProjectMigrator)}: Skip migrating {migrationSettings.ProjectDirectory}, it is already migrated.");
                return;
            }

            VerifyInputs(migrationRuleInputs, migrationSettings);

            SetupOutputDirectory(migrationSettings.ProjectDirectory, migrationSettings.OutputDirectory);

            _ruleSet.Apply(migrationSettings, migrationRuleInputs);
        }
Пример #13
0
        private MigrationRuleInputs ComputeMigrationRuleInputs(MigrationSettings migrationSettings)
        {
            var projectContexts = ProjectContext.CreateContextForEachFramework(migrationSettings.ProjectDirectory);
            var xprojFile       = migrationSettings.ProjectXProjFilePath ?? FindXprojFile(migrationSettings.ProjectDirectory);

            ProjectRootElement xproj = null;

            if (xprojFile != null)
            {
                xproj = ProjectRootElement.Open(xprojFile);
            }

            var templateMSBuildProject = migrationSettings.MSBuildProjectTemplate;

            if (templateMSBuildProject == null)
            {
                throw new Exception("Expected non-null MSBuildProjectTemplate in MigrationSettings");
            }

            var propertyGroup = templateMSBuildProject.AddPropertyGroup();
            var itemGroup     = templateMSBuildProject.AddItemGroup();

            return(new MigrationRuleInputs(projectContexts, templateMSBuildProject, itemGroup, propertyGroup, xproj));
        }
Пример #14
0
 private void VerifyInputs(MigrationRuleInputs migrationRuleInputs, MigrationSettings migrationSettings)
 {
     VerifyProject(migrationRuleInputs.ProjectContexts, migrationSettings.ProjectDirectory);
 }