private static (IProjectRootElement baselineRootElement, IProjectRootElement convertedRootElement) GetRootElementsForComparison(string projectToConvertPath, string projectBaselinePath) { var conversionLoader = new MSBuildComparisonWorkspaceLoader(projectToConvertPath, MSBuildComparisonWorkspaceType.Project); var conversionWorkspace = conversionLoader.LoadWorkspace(projectToConvertPath, noBackup: true); var baselineLoader = new MSBuildComparisonWorkspaceLoader(projectBaselinePath, MSBuildComparisonWorkspaceType.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("netcoreapp3.1", keepCurrentTfm: false, usePreviewSDK: false); return(baselineRootElement, convertedRootElement); }
public static int Run(string?project, string?workspace, string?msbuildPath, string?tfm, bool allowPreviews, bool diffOnly, bool noBackup, bool keepCurrentTfms) { if (!string.IsNullOrWhiteSpace(project) && !string.IsNullOrWhiteSpace(workspace)) { Console.WriteLine("Cannot specify both a project and a workspace."); return(-1); } if (!string.IsNullOrWhiteSpace(tfm) && keepCurrentTfms) { Console.WriteLine($"Both '{nameof(tfm)}' and '{nameof(keepCurrentTfms)}' cannot be specified. Please pick one."); return(-1); } try { msbuildPath = MSBuildHelpers.HookAssemblyResolveForMSBuild(msbuildPath); if (string.IsNullOrWhiteSpace(msbuildPath)) { Console.WriteLine("Could not find an MSBuild."); return(-1); } if (!string.IsNullOrWhiteSpace(tfm)) { tfm = tfm.Trim(); if (!TargetFrameworkHelper.IsValidTargetFramework(tfm)) { Console.WriteLine($"Invalid framework specified for --target-framework: '{tfm}'"); return(-1); } } var workspacePath = string.Empty; MSBuildComparisonWorkspaceType workspaceType; if (!string.IsNullOrWhiteSpace(project)) { workspacePath = Path.GetFullPath(project, Environment.CurrentDirectory); workspaceType = MSBuildComparisonWorkspaceType.Project; } else { var(isSolution, workspaceFilePath) = MSBuildComparisonWorkspaceFinder.FindWorkspace(Environment.CurrentDirectory, workspace); workspaceType = isSolution ? MSBuildComparisonWorkspaceType.Solution : MSBuildComparisonWorkspaceType.Project; workspacePath = workspaceFilePath; } var workspaceLoader = new MSBuildComparisonWorkspaceLoader(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(item.ProjectRootElement.FullPath, tfm, keepCurrentTfms, allowPreviews); } } } catch (Exception e) { Console.WriteLine(e.ToString()); return(-1); } Console.WriteLine("Conversion complete!"); return(0); }