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)); }
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)); }
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)); }
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); } }
public bool IsMigrated(MigrationSettings migrationSettings, MigrationRuleInputs migrationRuleInputs) { var outputName = migrationRuleInputs.DefaultProjectContext.GetProjectName(); var outputProject = Path.Combine(migrationSettings.OutputDirectory, outputName + ".csproj"); return(File.Exists(outputProject)); }
private void VerifyInputs( MigrationRuleInputs migrationRuleInputs, MigrationSettings migrationSettings, out List <string> warningMessages ) { VerifyProject(migrationRuleInputs.ProjectContexts, migrationSettings.ProjectDirectory, out warningMessages); }
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); } }
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)); }
public void Migrate(MigrationSettings migrationSettings) { var migrationRuleInputs = ComputeMigrationRuleInputs(migrationSettings); VerifyInputs(migrationRuleInputs, migrationSettings); SetupOutputDirectory(migrationSettings.ProjectDirectory, migrationSettings.OutputDirectory); _ruleSet.Apply(migrationSettings, migrationRuleInputs); }
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 { } } }
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)); }
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); }
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)); }
private void VerifyInputs(MigrationRuleInputs migrationRuleInputs, MigrationSettings migrationSettings) { VerifyProject(migrationRuleInputs.ProjectContexts, migrationSettings.ProjectDirectory); }