private string CreateRelativePathToFile(string projectDirectory, string filename) { List <string> pathSegments = new List <string>(); pathSegments.Add(projectDirectory); pathSegments.Add(filename); return(InspectorUtil.CreatePath(pathSegments)); }
public ProjectInspector(ProjectInspectionOptions options, NugetSearchService nugetService) { Options = options; NugetService = nugetService; if (Options == null) { throw new Exception("Must provide a valid options object."); } if (String.IsNullOrWhiteSpace(Options.ProjectDirectory)) { Options.ProjectDirectory = Directory.GetParent(Options.TargetPath).FullName; } if (String.IsNullOrWhiteSpace(Options.PackagesConfigPath)) { Options.PackagesConfigPath = CreateProjectPackageConfigPath(Options.ProjectDirectory); } if (String.IsNullOrWhiteSpace(Options.ProjectJsonPath)) { Options.ProjectJsonPath = CreateProjectJsonPath(Options.ProjectDirectory); } if (String.IsNullOrWhiteSpace(Options.ProjectJsonLockPath)) { Options.ProjectJsonLockPath = CreateProjectJsonLockPath(Options.ProjectDirectory); } if (String.IsNullOrWhiteSpace(Options.ProjectAssetsJsonPath)) { Options.ProjectAssetsJsonPath = CreateProjectAssetsJsonPath(Options.ProjectDirectory); } if (String.IsNullOrWhiteSpace(Options.ProjectName)) { Options.ProjectName = Path.GetFileNameWithoutExtension(Options.TargetPath); } if (String.IsNullOrWhiteSpace(Options.ProjectUniqueId)) { Options.ProjectUniqueId = Path.GetFileNameWithoutExtension(Options.TargetPath); } if (String.IsNullOrWhiteSpace(Options.VersionName)) { Options.VersionName = InspectorUtil.GetProjectAssemblyVersion(Options.ProjectDirectory); } }
public Model.Container GetContainer() { Console.WriteLine("Processing Solution: " + Options.TargetPath); var stopwatch = Stopwatch.StartNew(); Model.Container solution = new Model.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; List <string> projectPathSegments = new List <string>(); projectPathSegments.Add(solutionDirectory); projectPathSegments.Add(projectRelativePath); string projectPath = InspectorUtil.CreatePath(projectPathSegments); string projectName = project.Name; string projectId = projectName; if (duplicateNames.Contains(projectId)) { Console.WriteLine($"Duplicate project name '{projectName}' found. Using GUID instead."); projectId = 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, ProjectUniqueId = projectId, 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); }