private IEnumerable <(string pathPostfix, string contents)> GetDotNotations( FileInfo projectFile, ImmutableDictionary <string, string> globalProperties, string[] targets, string[] endNodes) { Console.WriteLine("Loading graph..."); var sw = Stopwatch.StartNew(); var graph = new ProjectGraph(new ProjectGraphEntryPoint(projectFile.FullName, globalProperties), ProjectCollection.GlobalProjectCollection); sw.Stop(); Console.WriteLine($@"{projectFile} loaded {graph.ProjectNodes.Count} node(s) in {sw.ElapsedMilliseconds}ms."); var entryTargetsPerNode = graph.GetTargetLists(targets); if (endNodes != null) { var endGraphNodes = graph.ProjectNodes.Where(n => endNodes.Any(en => n.ProjectInstance.FullPath.Contains(en))); var paths = GraphPaths.FindAllPathsBetween(graph.GraphRoots, endGraphNodes); var deduplicatedNodes = paths.SelectMany(p => p).ToHashSet(); yield return($"_PathsEndingIn_{string.Join(",", endNodes)}", GraphVis.Create(deduplicatedNodes, entryTargetsPerNode)); } yield return("", GraphVis.Create(graph, entryTargetsPerNode)); }
public void ResolvesViaSamePlatform() { using (var env = TestEnvironment.Create()) { TransientTestFile entryProject = CreateProjectFile(env, 1, extraContent: @"<PropertyGroup> <EnableDynamicPlatformResolution>true</EnableDynamicPlatformResolution> <Platform>x86</Platform> <PlatformLookupTable>x86=AnyCPU</PlatformLookupTable> </PropertyGroup> <ItemGroup> <ProjectReference Include=""$(MSBuildThisFileDirectory)2.proj"" > </ProjectReference> </ItemGroup>"); var proj2 = env.CreateFile("2.proj", @" <Project> <PropertyGroup> <PlatformLookupTable></PlatformLookupTable> <Platforms>x86;x64;AnyCPU</Platforms> </PropertyGroup> </Project>"); ProjectGraph graph = new ProjectGraph(entryProject.Path); GetFirstNodeWithProjectNumber(graph, 2).ProjectInstance.GlobalProperties["Platform"].ShouldBe("x86"); } }
internal static ProjectGraphNode?FindNodeByPath( this ProjectGraph graph, string projectPath) { return(graph.ProjectNodes .FirstOrDefault(n => n.ProjectInstance.FullPath == projectPath)); }
public static void AssertOuterBuildAsNonRoot( ProjectGraphNode outerBuild, ProjectGraph graph, Dictionary <string, string> additionalGlobalProperties = null, int expectedInnerBuildCount = 2) { additionalGlobalProperties ??= new Dictionary <string, string>(); AssertOuterBuildEvaluation(outerBuild, additionalGlobalProperties); outerBuild.ProjectReferences.ShouldBeEmpty(); outerBuild.ReferencingProjects.ShouldNotBeEmpty(); foreach (var outerBuildReferencer in outerBuild.ReferencingProjects) { var innerBuilds = outerBuildReferencer.ProjectReferences.Where( p => IsInnerBuild(p) && p.ProjectInstance.FullPath == outerBuild.ProjectInstance.FullPath).ToArray(); innerBuilds.Length.ShouldBe(expectedInnerBuildCount); foreach (var innerBuild in innerBuilds) { AssertInnerBuildEvaluation(innerBuild, true, additionalGlobalProperties); innerBuild.ReferencingProjects.ShouldContain(outerBuildReferencer); innerBuild.ReferencingProjects.ShouldNotContain(outerBuild); graph.TestOnly_Edges.HasEdge((outerBuild, innerBuild)).ShouldBeFalse(); var edgeToOuterBuild = graph.TestOnly_Edges[(outerBuildReferencer, outerBuild)];
internal static ProjectGraphNode?FindNodeByName( this ProjectGraph graph, string name) { return(graph.ProjectNodes .FirstOrDefault(n => n.GetProjectName().Equals(name, StringComparison.OrdinalIgnoreCase))); }
private static ProjectGraph CreateProjectGraphWithChildren(int numberChildren) { var project = new ProjectGraph(new Project()); AddChildren(project, numberChildren); return(project); }
/// <summary> /// Constructs a graph starting from the given graph entry points and execute all project and /// graph predictors against the resulting projects. /// </summary> /// <param name="projectGraph">Project graph to run predictions on.</param> /// <param name="projectPredictionCollector">The prediction collector to use.</param> public void PredictInputsAndOutputs( ProjectGraph projectGraph, IProjectPredictionCollector projectPredictionCollector) { projectGraph.ThrowIfNull(nameof(projectGraph)); projectPredictionCollector.ThrowIfNull(nameof(projectPredictionCollector)); // Special-case single-threaded prediction to avoid the overhead of Parallel.ForEach in favor of a simple loop. if (_options.MaxDegreeOfParallelism == 1) { foreach (var projectNode in projectGraph.ProjectNodes) { ExecuteAllPredictors(projectNode, _projectPredictors, _projectGraphPredictors, projectPredictionCollector); } } else { Parallel.ForEach( projectGraph.ProjectNodes.ToArray(), new ParallelOptions() { MaxDegreeOfParallelism = _options.MaxDegreeOfParallelism }, projectNode => ExecuteAllPredictors(projectNode, _projectPredictors, _projectGraphPredictors, projectPredictionCollector)); } }
public void FailsToResolve() { using (var env = TestEnvironment.Create()) { TransientTestFile entryProject = CreateProjectFile(env, 1, extraContent: @"<PropertyGroup> <EnableDynamicPlatformResolution>true</EnableDynamicPlatformResolution> <Platform>x86</Platform> <PlatformLookupTable>AnyCPU=x64</PlatformLookupTable> </PropertyGroup> <ItemGroup> <ProjectReference Include=""$(MSBuildThisFileDirectory)2.proj"" > </ProjectReference> </ItemGroup>"); var proj2 = env.CreateFile("2.proj", @" <Project> <PropertyGroup> <Platforms>x64</Platforms> </PropertyGroup> </Project>"); ProjectGraph graph = new ProjectGraph(entryProject.Path); // Here we are checking if platform is defined. in this case it should not be since Platorm would be set to the value this project defaults as // in order to avoid dual build errors we remove platform in order to avoid the edge case where a project has global platform set and does not have global platform set // yet still default to the same platform. GetFirstNodeWithProjectNumber(graph, 2).ProjectInstance.GlobalProperties.ContainsKey("Platform").ShouldBeFalse(); } }
public void FindNodesThatDependOn_ShouldFindAnyLevelDependency() { // Arrange using var dep2 = CreateProjectFile("dep2"); // dep1 depends on dep2 using var dep1 = CreateProjectFile("dep1", dep2); // root depends on dep1 using var projectThatChanged = CreateProjectFile("projectThatChanged", dep1); var graph = new ProjectGraph(projectThatChanged.Path); var dep2Node = graph.FindNodeByPath(dep2.Path); // Act var affected = graph.FindNodesThatDependOn(dep2Node).ToList(); // Assert Assert.Equal(2, affected.Count); var dep1Node = graph.FindNodeByPath(dep1.Path); var projectThatChangedNode = graph.FindNodeByPath(projectThatChanged.Path); Assert.Collection(affected, k => Assert.Equal(dep1Node, k), k => Assert.Equal(projectThatChangedNode, k) ); }
public void SolutionParserIgnoresProjectConfigurationsThatDoNotFullyMatchAnySolutionConfiguration() { var solutionContents = new SolutionFileBuilder { Projects = new Dictionary <string, string> { { "1", _env.CreateFile("1.csproj", string.Empty).Path } }, SolutionConfigurationPlatforms = new[] { new SolutionConfigurationInSolution("Foo", "Bar") }, ProjectConfigurations = new Dictionary <string, Dictionary <SolutionConfigurationInSolution, ProjectConfigurationInSolution> > { { "1", new Dictionary <SolutionConfigurationInSolution, ProjectConfigurationInSolution> { { new SolutionConfigurationInSolution("NonMatchingConfiguration", "NonMatchingPlatform"), new ProjectConfigurationInSolution("1a", "1b", true) }, { new SolutionConfigurationInSolution("Foo", "NonMatchingPlatform"), new ProjectConfigurationInSolution("1c", "1d", true) } } } } }.BuildSolution(); var solutionFile = _env.CreateFile("solution.sln", solutionContents).Path; var graph = new ProjectGraph(solutionFile); graph.ProjectNodes.ShouldBeEmpty(); }
public void GetTargetListsDefaultComplexPropagation() { var projectReferenceTargets = new Dictionary <string, string[]> { { "Build", new[] { "A", ".default" } }, { "X", new[] { "B", ".default" } }, { "Y", new[] { "C", ".default" } }, }; using (var env = TestEnvironment.Create()) { TransientTestFile entryProject = CreateProjectFile(env, 1, new[] { 2, 3, 4 }, projectReferenceTargets, defaultTargets: null); CreateProjectFile(env, 2, new[] { 5 }, projectReferenceTargets, defaultTargets: null); CreateProjectFile(env, 3, new[] { 6 }, projectReferenceTargets, defaultTargets: "X"); CreateProjectFile(env, 4, new[] { 7 }, projectReferenceTargets, defaultTargets: "Y"); CreateProjectFile(env, 5, defaultTargets: null); CreateProjectFile(env, 6, defaultTargets: null); CreateProjectFile(env, 7, defaultTargets: "Z;W"); var projectGraph = new ProjectGraph(entryProject.Path); projectGraph.ProjectNodes.Count.ShouldBe(7); IReadOnlyDictionary <ProjectGraphNode, ImmutableList <string> > targetLists = projectGraph.GetTargetLists(null); targetLists.Count.ShouldBe(projectGraph.ProjectNodes.Count); targetLists[GetNodeForProject(projectGraph, 1)].ShouldBe(new[] { "Build" }); targetLists[GetNodeForProject(projectGraph, 2)].ShouldBe(new[] { "A", "Build" }); targetLists[GetNodeForProject(projectGraph, 3)].ShouldBe(new[] { "A", "X" }); targetLists[GetNodeForProject(projectGraph, 4)].ShouldBe(new[] { "A", "Y" }); targetLists[GetNodeForProject(projectGraph, 5)].ShouldBe(new[] { "A", "Build" }); targetLists[GetNodeForProject(projectGraph, 6)].ShouldBe(new[] { "B", "Build" }); targetLists[GetNodeForProject(projectGraph, 7)].ShouldBe(new[] { "C", "Z", "W" }); } }
public void FindProjectsForFilePaths_WithMultipleFiles_ShouldFindSingleProject() { // Arrange using var project1 = CreateProjectFile( Path.Combine("somecontext", "project1", "project1") ); using var project2 = CreateProjectFile( Path.Combine("somecontext", "project2", "project2") ); var dummyFile = GetTemporaryFilePath( Path.Combine("somecontext", "project1", "Domain", "SomeEntity"), ".cs" ); var dummyFile2 = GetTemporaryFilePath( Path.Combine("somecontext", "project1", "Domain", "OtherEntity"), ".cs" ); var graph = new ProjectGraph(new string[] { project1.Path, project2.Path }); // Act var projects = graph.FindNodesContainingFiles(new[] { dummyFile, dummyFile2, }).ToList(); // Assert var project1Node = graph.FindNodeByPath(project1.Path); Assert.Single(projects); Assert.Equal(project1Node, projects.Single()); }
public void GetTargetListsDedupesTargets() { var projectReferenceTargets = new Dictionary <string, string[]> { { "A", new[] { "B", "X", "C" } }, { "B", new[] { "X", "Y" } }, { "C", new[] { "X", "Z" } }, }; using (var env = TestEnvironment.Create()) { TransientTestFile entryProject = CreateProjectFile(env, 1, new[] { 2 }, projectReferenceTargets); CreateProjectFile(env, 2, new[] { 3 }, projectReferenceTargets); CreateProjectFile(env, 3, Array.Empty <int>(), projectReferenceTargets); var projectGraph = new ProjectGraph(entryProject.Path); projectGraph.ProjectNodes.Count.ShouldBe(3); IReadOnlyDictionary <ProjectGraphNode, ImmutableList <string> > targetLists = projectGraph.GetTargetLists(new[] { "A" }); targetLists.Count.ShouldBe(projectGraph.ProjectNodes.Count); targetLists[GetNodeForProject(projectGraph, 1)].ShouldBe(new[] { "A" }); targetLists[GetNodeForProject(projectGraph, 2)].ShouldBe(new[] { "B", "X", "C" }); targetLists[GetNodeForProject(projectGraph, 3)].ShouldBe(new[] { "X", "Y", "Z" }); // Simplified from X, Y, X, Z } }
public void GetTargetListsForComplexGraph() { var projectReferenceTargets = new Dictionary <string, string[]> { { "A", new[] { "B" } }, { "B", new[] { "C" } }, { "C", new[] { "D" } }, { "D", new[] { "E" } }, }; using (var env = TestEnvironment.Create()) { TransientTestFile entryProject = CreateProjectFile(env, 1, new[] { 2, 3, 5 }, projectReferenceTargets); CreateProjectFile(env, 2, new[] { 4, 5 }, projectReferenceTargets); CreateProjectFile(env, 3, new[] { 5, 6 }, projectReferenceTargets); CreateProjectFile(env, 4, new[] { 5 }, projectReferenceTargets); CreateProjectFile(env, 5, new[] { 6 }, projectReferenceTargets); CreateProjectFile(env, 6, Array.Empty <int>(), projectReferenceTargets); var projectGraph = new ProjectGraph(entryProject.Path); projectGraph.ProjectNodes.Count.ShouldBe(6); IReadOnlyDictionary <ProjectGraphNode, ImmutableList <string> > targetLists = projectGraph.GetTargetLists(new[] { "A" }); targetLists.Count.ShouldBe(projectGraph.ProjectNodes.Count); targetLists[GetNodeForProject(projectGraph, 1)].ShouldBe(new[] { "A" }); targetLists[GetNodeForProject(projectGraph, 2)].ShouldBe(new[] { "B" }); targetLists[GetNodeForProject(projectGraph, 3)].ShouldBe(new[] { "B" }); targetLists[GetNodeForProject(projectGraph, 4)].ShouldBe(new[] { "C" }); targetLists[GetNodeForProject(projectGraph, 5)].ShouldBe(new[] { "B", "C", "D" }); targetLists[GetNodeForProject(projectGraph, 6)].ShouldBe(new[] { "C", "D", "E" }); } }
public void ConstructWithDifferentGlobalProperties() { using (var env = TestEnvironment.Create()) { TransientTestFile entryProject = CreateProjectFile(env, 1, new[] { 2, 3 }); env.CreateFile("2.proj", @" <Project> <ItemGroup> <ProjectReference Include=""4.proj"" /> </ItemGroup> </Project>"); env.CreateFile("3.proj", @" <Project> <ItemGroup> <ProjectReference Include=""4.proj"" AdditionalProperties=""A=B"" /> </ItemGroup> </Project>"); CreateProjectFile(env, 4); ProjectGraph graph = new ProjectGraph(entryProject.Path); // Project 4 requires 2 nodes graph.ProjectNodes.Count.ShouldBe(5); // Projects 2 and 3 both reference project 4, but with different properties, so they should not point to the same node. GetNodeForProject(graph, 2).ProjectReferences.First().ShouldNotBe(GetNodeForProject(graph, 3).ProjectReferences.First()); GetNodeForProject(graph, 2).ProjectReferences.First().ProjectInstance.FullPath.ShouldEndWith("4.proj"); GetNodeForProject(graph, 2).ProjectReferences.First().GlobalProperties.ShouldBeEmpty(); GetNodeForProject(graph, 3).ProjectReferences.First().ProjectInstance.FullPath.ShouldEndWith("4.proj"); GetNodeForProject(graph, 3).ProjectReferences.First().GlobalProperties.ShouldNotBeEmpty(); } }
public void GetTargetListsAggregatesFromMultipleEdges() { using (var env = TestEnvironment.Create()) { TransientTestFile entryProject = CreateProjectFile(env, 1, new[] { 2, 3 }, new Dictionary <string, string[]> { { "A", new[] { "B" } } }); CreateProjectFile(env, 2, new[] { 4 }, new Dictionary <string, string[]> { { "B", new[] { "C" } } }); CreateProjectFile(env, 3, new[] { 4 }, new Dictionary <string, string[]> { { "B", new[] { "D" } } }); CreateProjectFile(env, 4); var projectGraph = new ProjectGraph(entryProject.Path); projectGraph.ProjectNodes.Count.ShouldBe(4); IReadOnlyDictionary <ProjectGraphNode, ImmutableList <string> > targetLists = projectGraph.GetTargetLists(new[] { "A" }); targetLists.Count.ShouldBe(projectGraph.ProjectNodes.Count); targetLists[GetNodeForProject(projectGraph, 1)].ShouldBe(new[] { "A" }); targetLists[GetNodeForProject(projectGraph, 2)].ShouldBe(new[] { "B" }); targetLists[GetNodeForProject(projectGraph, 3)].ShouldBe(new[] { "B" }); targetLists[GetNodeForProject(projectGraph, 4)].ShouldBe(new[] { "C", "D" }); // From B => C and B => D } }
public void ConstructWithSameEffectiveProperties() { using (var env = TestEnvironment.Create()) { TransientTestFile entryProject = CreateProjectFile(env, 1, new[] { 2, 3 }); env.CreateFile("2.proj", @" <Project> <ItemGroup> <ProjectReference Include=""4.proj"" AdditionalProperties=""Foo=Bar"" /> </ItemGroup> </Project>"); env.CreateFile("3.proj", @" <Project> <ItemGroup> <ProjectReference Include=""4.proj"" GlobalPropertiesToRemove=""DoesNotExist"" /> </ItemGroup> </Project>"); CreateProjectFile(env, 4); ProjectGraph graph = new ProjectGraph( entryProject.Path, new Dictionary <string, string> { { "Foo", "Bar" } }); // Project 4 does not require 2 nodes graph.ProjectNodes.Count.ShouldBe(4); // The project references end up using the same effective properties GetNodeForProject(graph, 2).ProjectReferences.First().ShouldBe(GetNodeForProject(graph, 3).ProjectReferences.First()); } }
internal static string ToDot(ProjectGraph graph, Func <ProjectGraphNode, string> nodeIdProvider) { var nodeIds = new ConcurrentDictionary <ProjectGraphNode, string>(); var sb = new StringBuilder(); sb.Append("digraph g\n{\n\tnode [shape=box]\n"); foreach (var node in graph.ProjectNodes) { var nodeId = nodeIds.GetOrAdd(node, (n, idProvider) => idProvider(n), nodeIdProvider); var nodeName = Path.GetFileNameWithoutExtension(node.ProjectInstance.FullPath); var globalPropertiesString = string.Join("<br/>", node.ProjectInstance.GlobalProperties.OrderBy(kvp => kvp.Key).Select(kvp => $"{kvp.Key}={kvp.Value}")); sb.AppendLine($"\t{nodeId} [label=<{nodeName}<br/>{globalPropertiesString}>]"); foreach (var reference in node.ProjectReferences) { var referenceId = nodeIds.GetOrAdd(reference, (n, idProvider) => idProvider(n), nodeIdProvider); sb.AppendLine($"\t{nodeId} -> {referenceId}"); } } sb.Append("}"); return(sb.ToString()); }
/// <summary> /// Constructs a graph starting from the given graph entry points and execute all project and /// graph predictors against the resulting projects. /// </summary> /// <param name="projectGraph">Project graph to run predictions on.</param> /// <returns>An object describing all predicted inputs and outputs.</returns> public ProjectGraphPredictions PredictInputsAndOutputs(ProjectGraph projectGraph) { var projectGraphPredictionCollector = new DefaultProjectGraphPredictionCollector(projectGraph); PredictInputsAndOutputs(projectGraph, projectGraphPredictionCollector); return(projectGraphPredictionCollector.GraphPredictions); }
public NugetModel(string version, IList <ProjectFile> files) { Version = version; Files = files; Graph = new ProjectGraph(); PopulateGraph(); }
/// <summary> /// Constructs a GraphBuildRequestData for build requests based on a project graph. /// </summary> /// <param name="projectGraph">The graph to build.</param> /// <param name="targetsToBuild">The targets to build.</param> /// <param name="hostServices">The host services to use, if any. May be null.</param> /// <param name="flags">Flags controlling this build request.</param> public GraphBuildRequestData(ProjectGraph projectGraph, ICollection <string> targetsToBuild, HostServices hostServices, BuildRequestDataFlags flags) : this(targetsToBuild, hostServices, flags) { ErrorUtilities.VerifyThrowArgumentNull(projectGraph, nameof(projectGraph)); ProjectGraph = projectGraph; }
private void AssertPredictionsMadeForEveryNode(ProjectGraph projectGraph, ProjectGraphPredictions graphPredictions) { Assert.Equal(projectGraph.ProjectNodes.Count, graphPredictions.PredictionsPerNode.Count); foreach (ProjectGraphNode node in projectGraph.ProjectNodes) { graphPredictions.PredictionsPerNode.ContainsKey(node); } }
public static string Create(ProjectGraph graph, GraphVisOptions options) { // I don't really remember why I did the hash thing. I think I was concerned with duplicate nodes? var projects = new ConcurrentDictionary <string, ProjectGraphNode>(); var selectedProjects = graph.ProjectNodes.Where(p => !p.ProjectInstance.FullPath.Contains("dirs.proj")); return(Create(selectedProjects, options)); }
private void PopulateTree(ProjectGraph graph) { Invoke(new Action(() => _treeVew.Nodes.Clear())); foreach (var root in graph.GraphRoots) { Invoke(new Action(() => _treeVew.Nodes.Add(AdaptGraphNode(root)))); } }
public static string Create( ProjectGraph graph, GraphVisOptions options, IReadOnlyDictionary <ProjectGraphNode, ImmutableList <string> > entryTargetsPerNode = null) { var selectedProjects = graph.ProjectNodes.Where(p => !p.ProjectInstance.FullPath.Contains("dirs.proj")); return(Create(selectedProjects, options, entryTargetsPerNode)); }
public void ConstructWithSingleNode() { using (var env = TestEnvironment.Create()) { TransientTestFile entryProject = CreateProjectFile(env, 1); var projectGraph = new ProjectGraph(entryProject.Path); projectGraph.ProjectNodes.Count.ShouldBe(1); projectGraph.ProjectNodes.First().ProjectInstance.FullPath.ShouldBe(entryProject.Path); } }
public void ConstructWithNoNodes() { var projectGraph = new ProjectGraph(Enumerable.Empty <ProjectGraphEntryPoint>()); projectGraph.ProjectNodes.ShouldBeEmpty(); projectGraph.EntryPointNodes.ShouldBeEmpty(); projectGraph.GraphRoots.ShouldBeEmpty(); projectGraph.ProjectNodesTopologicallySorted.ShouldBeEmpty(); projectGraph.GetTargetLists(new [] { "restore", "build" }).ShouldBeEmpty(); }
private static int BuildWithBuildManager(IReadOnlyList <string> args) { Trace.Assert(args[_executionTypeIndex] == BuildManagerArg); Trace.Assert(_executionTypeIndex + 1 <= args.Count - 1); var projectRootIndex = _executionTypeIndex + 1; var projectExtensionIndex = _executionTypeIndex + 2; var solutionFileIndex = _executionTypeIndex + 3; var projectRoot = args[projectRootIndex]; var projectFileExtension = projectExtensionIndex <= args.Count - 1 ? args[projectExtensionIndex] : "csproj"; var solutionFile = solutionFileIndex == args.Count - 1 ? args[solutionFileIndex] : null; Trace.Assert(Directory.Exists(projectRoot), $"Directory does not exist: {projectRoot}"); Trace.Assert(projectFileExtension[0] != '.'); var projectFiles = GetProjects(projectRoot, solutionFile, projectFileExtension); using (var buildManager = new BuildManager()) { var graph = new ProjectGraph(projectFiles); var graphRequestData = new GraphBuildRequestData(graph, new[] { "Build" }); var parameters = new BuildParameters() { Loggers = GetLoggers(Path.Combine(projectRoot, "logFile")), IsolateProjects = true, LogTaskInputs = true, LogInitialPropertiesAndItems = true, MaxNodeCount = 1 }; buildManager.BeginBuild(parameters); try { var request = buildManager.PendBuildRequest(graphRequestData); var graphResult = request.Execute(); return(graphResult.OverallResult == BuildResultCode.Success ? 0 : 1); } finally { buildManager.EndBuild(); } } }
private static void AddChildren(ProjectGraph project, int numberChildren) { var children = new List <ProjectGraph>(); for (var i = 0; i < numberChildren; i++) { var child = new ProjectGraph(new Project()); children.Add(child); } project.ProjectDependencies = children; }
public void ConstructWithMultipleNodes() { using (var env = TestEnvironment.Create()) { CreateProjectFile(env, 1, new[] { 4, 5 }); TransientTestFile entryProject = CreateProjectFile(env, 2, new[] { 3, 5, 6 }); CreateProjectFile(env, 3); CreateProjectFile(env, 4); CreateProjectFile(env, 5, new[] { 7 }); CreateProjectFile(env, 6, new[] { 1 }); CreateProjectFile(env, 7); ProjectGraph graph = new ProjectGraph(entryProject.Path); graph.ProjectNodes.Count.ShouldBe(7); ProjectGraphNode node1 = GetNodeForProject(graph, 1); ProjectGraphNode node2 = GetNodeForProject(graph, 2); ProjectGraphNode node3 = GetNodeForProject(graph, 3); ProjectGraphNode node4 = GetNodeForProject(graph, 4); ProjectGraphNode node5 = GetNodeForProject(graph, 5); ProjectGraphNode node6 = GetNodeForProject(graph, 6); ProjectGraphNode node7 = GetNodeForProject(graph, 7); node1.ProjectReferences.Count.ShouldBe(2); node2.ProjectReferences.Count.ShouldBe(3); node3.ProjectReferences.Count.ShouldBe(0); node4.ProjectReferences.Count.ShouldBe(0); node5.ProjectReferences.Count.ShouldBe(1); node6.ProjectReferences.Count.ShouldBe(1); node7.ProjectReferences.Count.ShouldBe(0); node1.ReferencingProjects.Count.ShouldBe(1); node2.ReferencingProjects.Count.ShouldBe(0); node3.ReferencingProjects.Count.ShouldBe(1); node4.ReferencingProjects.Count.ShouldBe(1); node5.ReferencingProjects.Count.ShouldBe(2); node6.ReferencingProjects.Count.ShouldBe(1); node7.ReferencingProjects.Count.ShouldBe(1); // confirm that there is a path from 2 -> 6 -> 1 -> 5 -> 7 node2.ProjectReferences.ShouldContain(node6); node6.ProjectReferences.ShouldContain(node1); node1.ProjectReferences.ShouldContain(node5); node5.ProjectReferences.ShouldContain(node7); // confirm that there is a path from 7 -> 5 -> 1 -> 6 -> 2 using ReferencingProjects node7.ReferencingProjects.ShouldContain(node5); node5.ReferencingProjects.ShouldContain(node1); node1.ReferencingProjects.ShouldContain(node6); node6.ReferencingProjects.ShouldContain(node2); } }
private void BuildGraph() { var graph = new ProjectGraph(); graph.AddVertexRange(Projects); foreach (var project in Projects) { var refProj = project.ReferencedProjects.Select(rp => Projects.Single(p => p.GUID == rp)); refProj.ToList().ForEach(p => graph.AddEdge(new ProjectEdge("1", project, p))); } Graph = graph; }
private void BuildTestGraph() { Graph = new ProjectGraph(); var existingVertices = new List<Project>() { new Project(Guid.NewGuid(), "CppDll", Environment.CurrentDirectory, Language.Cpp, OutputType.Dll, null), new Project(Guid.NewGuid(), "CppLib", Environment.CurrentDirectory, Language.Cpp, OutputType.Lib, null), new Project(Guid.NewGuid(), "CppExe", Environment.CurrentDirectory, Language.Cpp, OutputType.ExeConsole, null), new Project(Guid.NewGuid(), "C# Dll", Environment.CurrentDirectory, Language.Csharp, OutputType.Dll, null), new Project(Guid.NewGuid(), "C# win exe", Environment.CurrentDirectory, Language.Csharp, OutputType.ExeWindow, null), new Project(Guid.NewGuid(), "C# console exe", Environment.CurrentDirectory, Language.Csharp, OutputType.ExeConsole, null) }; foreach (var vertex in existingVertices) _graph.AddVertex(vertex); AddProjectReference(existingVertices[2], existingVertices[0]); AddProjectReference(existingVertices[2], existingVertices[1]); AddProjectReference(existingVertices[4], existingVertices[3]); AddProjectReference(existingVertices[4], existingVertices[3]); AddProjectReference(existingVertices[3], existingVertices[0]); AddProjectReference(existingVertices[3], existingVertices[1]); AddProjectReference(existingVertices[5], existingVertices[3]); }