コード例 #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
ファイル: ProjectMigrator.cs プロジェクト: wen101016/cli
        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
ファイル: DefaultMigrationRuleSet.cs プロジェクト: jgalar/cli
 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
ファイル: ProjectMigrator.cs プロジェクト: serdna27/cli
        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
ファイル: ProjectMigrator.cs プロジェクト: tmat/cli-migrate
 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
ファイル: ProjectMigrator.cs プロジェクト: rajkumar42/cli
        public void Migrate(MigrationSettings migrationSettings)
        {
            var migrationRuleInputs = ComputeMigrationRuleInputs(migrationSettings);

            VerifyInputs(migrationRuleInputs, migrationSettings);

            SetupOutputDirectory(migrationSettings.ProjectDirectory, migrationSettings.OutputDirectory);

            _ruleSet.Apply(migrationSettings, migrationRuleInputs);
        }
コード例 #10
0
ファイル: ProjectMigrator.cs プロジェクト: serdna27/cli
        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
ファイル: ProjectMigrator.cs プロジェクト: rajkumar42/cli
        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
ファイル: ProjectMigrator.cs プロジェクト: rajkumar42/cli
 private void VerifyInputs(MigrationRuleInputs migrationRuleInputs, MigrationSettings migrationSettings)
 {
     VerifyProject(migrationRuleInputs.ProjectContexts, migrationSettings.ProjectDirectory);
 }