public virtual int DoUpgradeProject_CheckOnly(string projectFileName, IVsUpgradeLogger upgradeLogger, out __VSPPROJECTUPGRADEVIAFACTORYREPAIRFLAGS upgradeRequired, out Guid newProjectFactory, out uint upgradeCapabilityFlags) { newProjectFactory = GetType().GUID; var project = ProjectRootElement.Open(projectFileName); // enable Side-by-Side and CopyBackup support upgradeCapabilityFlags = (uint)(__VSPPROJECTUPGRADEVIAFACTORYFLAGS.PUVFF_BACKUPSUPPORTED | __VSPPROJECTUPGRADEVIAFACTORYFLAGS.PUVFF_COPYBACKUP | __VSPPROJECTUPGRADEVIAFACTORYFLAGS.PUVFF_SXSBACKUP); #if FX_ATLEAST_45 if (this.buildEngine.GetLoadedProjects(projectFileName).Count > 0) { // project has already been loaded upgradeRequired = __VSPPROJECTUPGRADEVIAFACTORYREPAIRFLAGS.VSPUVF_PROJECT_NOREPAIR; return(VSConstants.S_OK); } var projectInspector = new ProjectInspector(projectFileName); if (projectInspector.IsPoisoned(Site)) { // poisoned project cannot be opened (does not require upgrade) upgradeRequired = __VSPPROJECTUPGRADEVIAFACTORYREPAIRFLAGS.VSPUVF_PROJECT_NOREPAIR; return(VSConstants.S_OK); } #endif // only upgrade known tool versions. #if FX_ATLEAST_45 if (string.Equals("4.0", project.ToolsVersion, StringComparison.Ordinal)) { // For 4.0, we need to take a deeper look. The logic is in // vsproject\xmake\XMakeConversion\ProjectFileConverter.cs var projectConverter = new Microsoft.Build.Conversion.ProjectFileConverter(); projectConverter.OldProjectFile = projectFileName; projectConverter.NewProjectFile = projectFileName; if (projectConverter.FSharpSpecificConversions(false)) { upgradeRequired = projectInspector.IsLikeDev10MinusProject() ? __VSPPROJECTUPGRADEVIAFACTORYREPAIRFLAGS.VSPUVF_PROJECT_ONEWAYUPGRADE : __VSPPROJECTUPGRADEVIAFACTORYREPAIRFLAGS.VSPUVF_PROJECT_SAFEREPAIR; return(VSConstants.S_OK); } else { upgradeRequired = __VSPPROJECTUPGRADEVIAFACTORYREPAIRFLAGS.VSPUVF_PROJECT_NOREPAIR; return(VSConstants.S_OK); } } else #endif if (string.Equals("3.5", project.ToolsVersion, StringComparison.Ordinal) || string.Equals("2.0", project.ToolsVersion, StringComparison.Ordinal)) { // For 3.5 or 2.0, we always need to upgrade. upgradeRequired = __VSPPROJECTUPGRADEVIAFACTORYREPAIRFLAGS.VSPUVF_PROJECT_ONEWAYUPGRADE; return(VSConstants.S_OK); } upgradeRequired = __VSPPROJECTUPGRADEVIAFACTORYREPAIRFLAGS.VSPUVF_PROJECT_NOREPAIR; return(VSConstants.S_OK); }
public virtual int DoUpgradeProject_CheckOnly(string projectFileName, IVsUpgradeLogger upgradeLogger, out __VSPPROJECTUPGRADEVIAFACTORYREPAIRFLAGS upgradeRequired, out Guid newProjectFactory, out uint upgradeCapabilityFlags) { newProjectFactory = GetType().GUID; var project = ProjectRootElement.Open(projectFileName); // enable Side-by-Side and CopyBackup support upgradeCapabilityFlags = (uint)(__VSPPROJECTUPGRADEVIAFACTORYFLAGS.PUVFF_BACKUPSUPPORTED | __VSPPROJECTUPGRADEVIAFACTORYFLAGS.PUVFF_COPYBACKUP | __VSPPROJECTUPGRADEVIAFACTORYFLAGS.PUVFF_SXSBACKUP); #if FX_ATLEAST_45 if (this.buildEngine.GetLoadedProjects(projectFileName).Count > 0) { // project has already been loaded upgradeRequired = __VSPPROJECTUPGRADEVIAFACTORYREPAIRFLAGS.VSPUVF_PROJECT_NOREPAIR; return VSConstants.S_OK; } var projectInspector = new ProjectInspector(projectFileName); if (projectInspector.IsPoisoned(Site)) { // poisoned project cannot be opened (does not require upgrade) upgradeRequired = __VSPPROJECTUPGRADEVIAFACTORYREPAIRFLAGS.VSPUVF_PROJECT_NOREPAIR; return VSConstants.S_OK; } #endif // only upgrade known tool versions. #if FX_ATLEAST_45 if (string.Equals("4.0", project.ToolsVersion, StringComparison.Ordinal)) { // For 4.0, we need to take a deeper look. The logic is in // vsproject\xmake\XMakeConversion\ProjectFileConverter.cs var projectConverter = new Microsoft.Build.Conversion.ProjectFileConverter(); projectConverter.OldProjectFile = projectFileName; projectConverter.NewProjectFile = projectFileName; if (projectConverter.FSharpSpecificConversions(false)) { upgradeRequired = projectInspector.IsLikeDev10MinusProject() ? __VSPPROJECTUPGRADEVIAFACTORYREPAIRFLAGS.VSPUVF_PROJECT_ONEWAYUPGRADE : __VSPPROJECTUPGRADEVIAFACTORYREPAIRFLAGS.VSPUVF_PROJECT_SAFEREPAIR; return VSConstants.S_OK; } else { upgradeRequired = __VSPPROJECTUPGRADEVIAFACTORYREPAIRFLAGS.VSPUVF_PROJECT_NOREPAIR; return VSConstants.S_OK; } } else #endif if (string.Equals("3.5", project.ToolsVersion, StringComparison.Ordinal) || string.Equals("2.0", project.ToolsVersion, StringComparison.Ordinal)) { // For 3.5 or 2.0, we always need to upgrade. upgradeRequired = __VSPPROJECTUPGRADEVIAFACTORYREPAIRFLAGS.VSPUVF_PROJECT_ONEWAYUPGRADE; return VSConstants.S_OK; } upgradeRequired = __VSPPROJECTUPGRADEVIAFACTORYREPAIRFLAGS.VSPUVF_PROJECT_NOREPAIR; return VSConstants.S_OK; }
public Container GetContainer() { Console.WriteLine("Processing Solution: " + Options.TargetPath); var stopwatch = Stopwatch.StartNew(); Container solution = new Container(); solution.Name = Options.SolutionName; solution.SourcePath = Options.TargetPath; solution.Type = "Solution"; try { List <ProjectFile> projectFiles = FindProjectFilesFromSolutionFile(Options.TargetPath, ExcludedProjectTypeGUIDs); Console.WriteLine("Parsed Solution File"); if (projectFiles.Count > 0) { string solutionDirectory = Path.GetDirectoryName(Options.TargetPath); Console.WriteLine("Solution directory: {0}", solutionDirectory); var duplicateNames = projectFiles .GroupBy(project => project.Name) .Where(group => group.Count() > 1) .Select(group => group.Key); var duplicatePaths = projectFiles .GroupBy(project => project.Path) .Where(group => group.Count() > 1) .Select(group => group.Key); foreach (ProjectFile project in projectFiles) { try { string projectRelativePath = project.Path; string projectPath = PathUtil.Combine(solutionDirectory, projectRelativePath); string projectName = project.Name; if (duplicateNames.Contains(projectName)) { Console.WriteLine($"Duplicate project name '{projectName}' found. Using GUID instead."); projectName = project.GUID; } Boolean projectFileExists = false; try { projectFileExists = File.Exists(projectPath); } catch (Exception e) { Console.WriteLine("Skipping unknown project path: " + projectPath); continue; } if (!projectFileExists) { Console.WriteLine("Skipping non-existent project path: " + projectPath); continue; } ProjectInspector projectInspector = new ProjectInspector(new ProjectInspectionOptions(Options) { ProjectName = projectName, TargetPath = projectPath }, NugetService); InspectionResult projectResult = projectInspector.Inspect(); if (projectResult != null && projectResult.Containers != null) { solution.Children.AddRange(projectResult.Containers); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); if (Options.IgnoreFailure) { Console.WriteLine("Error inspecting project: {0}", project.Path); Console.WriteLine("Error inspecting project. Cause: {0}", ex); } else { throw ex; } } } } else { Console.WriteLine("No project data found for solution {0}", Options.TargetPath); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); if (Options.IgnoreFailure) { Console.WriteLine("Error executing Build BOM task. Cause: {0}", ex); } else { throw ex; } } if (solution != null && solution.Children != null) { Console.WriteLine("Found " + solution.Children.Count + " children."); } Console.WriteLine("Finished processing solution: " + Options.TargetPath); Console.WriteLine("Took " + stopwatch.ElapsedMilliseconds + " ms to process."); return(solution); }