private static (IProjectRootElement baselineRootElement, IProjectRootElement convertedRootElement) GetRootElementsForComparison(string projectToConvertPath, string projectBaselinePath) { var conversionLoader = new MSBuildWorkspaceLoader(projectToConvertPath, MSBuildWorkspaceType.Project); var conversionWorkspace = conversionLoader.LoadWorkspace(projectToConvertPath, noBackup: true); var baselineLoader = new MSBuildWorkspaceLoader(projectBaselinePath, MSBuildWorkspaceType.Project); var baselineRootElement = baselineLoader.GetRootElementFromProjectFile(projectBaselinePath); var item = conversionWorkspace.WorkspaceItems.Single(); var converter = new Converter(item.UnconfiguredProject, item.SdkBaselineProject, item.ProjectRootElement); var convertedRootElement = converter.ConvertProjectFile(); return(baselineRootElement, convertedRootElement); }
public static int Run(string?project, string?workspace, string?msbuildPath, string?tfm, bool allowPreviews, bool diffOnly, bool noBackup) { if (!string.IsNullOrWhiteSpace(project) && !string.IsNullOrWhiteSpace(workspace)) { Console.WriteLine("Cannot specify both a project and a workspace."); return(-1); } try { msbuildPath = MSBuildHelpers.HookAssemblyResolveForMSBuild(msbuildPath); if (string.IsNullOrWhiteSpace(msbuildPath)) { Console.WriteLine("Could not find an MSBuild."); return(-1); } if (tfm is null) { tfm = TargetFrameworkHelper.FindHighestInstalledTargetFramework(allowPreviews); } else { tfm = tfm.Trim(); if (!TargetFrameworkHelper.IsValidTargetFramework(tfm)) { Console.WriteLine($"Invalid framework specified for --target-framework: '{tfm}'"); return(-1); } } var workspacePath = string.Empty; MSBuildWorkspaceType workspaceType; if (!string.IsNullOrWhiteSpace(project)) { workspacePath = Path.GetFullPath(project, Environment.CurrentDirectory); workspaceType = MSBuildWorkspaceType.Project; } else { var(isSolution, workspaceFilePath) = MSBuildWorkspaceFinder.FindWorkspace(Environment.CurrentDirectory, workspace); workspaceType = isSolution ? MSBuildWorkspaceType.Solution : MSBuildWorkspaceType.Project; workspacePath = workspaceFilePath; } var workspaceLoader = new MSBuildWorkspaceLoader(workspacePath, workspaceType); // do not create backup if --diff-only specified noBackup = noBackup || diffOnly; var msbuildWorkspace = workspaceLoader.LoadWorkspace(workspacePath, noBackup); foreach (var item in msbuildWorkspace.WorkspaceItems) { if (diffOnly) { var differ = new Differ(item.UnconfiguredProject.FirstConfiguredProject, item.SdkBaselineProject.Project.FirstConfiguredProject); differ.GenerateReport(Directory.GetParent(workspacePath).FullName); } else { var converter = new Converter(item.UnconfiguredProject, item.SdkBaselineProject, item.ProjectRootElement); converter.Convert(tfm, item.ProjectRootElement.FullPath); } } } catch (Exception e) { Console.WriteLine(e.ToString()); return(-1); } Console.WriteLine("Conversion complete!"); return(0); }
public static int Run(string project, string workspace, string msbuildPath, bool diffOnly, bool noBackup) { if (!string.IsNullOrWhiteSpace(project) && !string.IsNullOrWhiteSpace(workspace)) { Console.WriteLine("Cannot specify both a project and a workspace."); return(-1); } try { msbuildPath = MSBuildHelpers.HookAssemblyResolveForMSBuild(msbuildPath); if (string.IsNullOrWhiteSpace(msbuildPath)) { Console.WriteLine("Could not find an MSBuild."); return(-1); } var currentDirectory = Environment.CurrentDirectory; var workspacePath = string.Empty; MSBuildWorkspaceType workspaceType; if (!string.IsNullOrWhiteSpace(project)) { workspacePath = Path.GetFullPath(project, Environment.CurrentDirectory); workspaceType = MSBuildWorkspaceType.Project; } else if (!string.IsNullOrWhiteSpace(workspace)) { var(isSolution, workspaceFilePath) = MSBuildWorkspaceFinder.FindWorkspace(currentDirectory, workspace); workspaceType = isSolution ? MSBuildWorkspaceType.Solution : MSBuildWorkspaceType.Project; workspacePath = workspaceFilePath; } else { throw new ArgumentException("No valid arguments to fulfill a workspace are given."); } var workspaceLoader = new MSBuildWorkspaceLoader(workspacePath, workspaceType); var msbuildWorkspace = workspaceLoader.LoadWorkspace(workspacePath, noBackup); foreach (var item in msbuildWorkspace.WorkspaceItems) { if (diffOnly) { var differ = new Differ(item.UnconfiguredProject.FirstConfiguredProject, item.SdkBaselineProject.Project.FirstConfiguredProject); differ.GenerateReport(Directory.GetParent(workspacePath).FullName); } else { var converter = new Converter(item.UnconfiguredProject, item.SdkBaselineProject, item.ProjectRootElement); converter.Convert(item.ProjectRootElement.FullPath); } } } catch (Exception e) { Console.WriteLine(e.ToString()); return(-1); } Console.WriteLine("Conversion complete!"); return(0); }