public void Init() { var teamCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://logpmtfs01v:8080/tfs/Logitravel")); var buildServer = teamCollection.GetService<IBuildServer>(); var commonStructureService = teamCollection.GetService<Microsoft.TeamFoundation.Server.ICommonStructureService>(); var buildDefinitionResults = Helpers.QueryBuildDefinitions(commonStructureService, buildServer, buildName: ""); var buildDefinition = buildDefinitionResults.FirstOrDefault().Definitions.FirstOrDefault(bd => bd != null && bd.QueueStatus == DefinitionQueueStatus.Enabled); Graph = new DependencyGraph<ProjectInfo>(); var ti = new TeamCollectionInfo(teamCollection); var bi = new BuildDefinitionInfo(ti, buildDefinition); var si = new SolutionInfo(bi, "S1"); var pA = new ProjectInfo(si) { ProjectGuid = Guid.Empty, GeneratedAssembly = "A", ReferencedProjects = new System.Collections.Generic.HashSet<Guid>() }; var pB = new ProjectInfo(si) { ProjectGuid = Guid.Empty, GeneratedAssembly = "B", ReferencedProjects = new System.Collections.Generic.HashSet<Guid>() }; var pC = new ProjectInfo(si) { ProjectGuid = Guid.Empty, GeneratedAssembly = "C", ReferencedProjects = new System.Collections.Generic.HashSet<Guid>() }; var pD = new ProjectInfo(si) { ProjectGuid = Guid.Empty, GeneratedAssembly = "D", ReferencedProjects = new System.Collections.Generic.HashSet<Guid>() }; var pE = new ProjectInfo(si) { ProjectGuid = Guid.Empty, GeneratedAssembly = "E", ReferencedProjects = new System.Collections.Generic.HashSet<Guid>() }; var pF = new ProjectInfo(si) { ProjectGuid = Guid.Empty, GeneratedAssembly = "F", ReferencedProjects = new System.Collections.Generic.HashSet<Guid>() }; var pG = new ProjectInfo(si) { ProjectGuid = Guid.Empty, GeneratedAssembly = "G", ReferencedProjects = new System.Collections.Generic.HashSet<Guid>() }; var pH = new ProjectInfo(si) { ProjectGuid = Guid.Empty, GeneratedAssembly = "H", ReferencedProjects = new System.Collections.Generic.HashSet<Guid>() }; Graph.Nodes.Add(pA); Graph.Nodes.Add(pB); Graph.Nodes.Add(pC); Graph.Nodes.Add(pD); Graph.Nodes.Add(pE); Graph.Nodes.Add(pF); Graph.Nodes.Add(pG); Graph.Nodes.Add(pH); Graph.AddDependency(pA, pC); Graph.AddDependency(pA, pF); Graph.AddDependency(pA, pD); Graph.AddDependency(pD, pF); Graph.AddDependency(pD, pG); Graph.AddDependency(pB, pD); Graph.AddDependency(pB, pG); Graph.AddDependency(pE, pG); Graph.AddDependency(pG, pF); Graph.AddDependency(pG, pH); }
private AssemblyInfo.ProjectInfo ProcessProject(SolutionInfo solutionInfo, string projectFile) { if (Verbose) Console.WriteLine("Project: '{0}'", projectFile); var projectInfo = new AssemblyInfo.ProjectInfo(solutionInfo); try { using (var projectFileStream = ReadFileFromVersionControlServer(solutionInfo.BuildDefinition.TeamCollection.Collection, projectFile)) { using (var reader = System.Xml.XmlReader.Create(projectFileStream)) { var project = new Project(reader, null, null, null, new ProjectCollection(), ProjectLoadSettings.IgnoreMissingImports); var assemblyName = project.Properties.FirstOrDefault(x => x.Name == "AssemblyName")?.EvaluatedValue; var projectGuidProperty = project.Properties.FirstOrDefault(x => x.Name == "ProjectGuid"); if (projectGuidProperty != null) { var projectGuid = new Guid(projectGuidProperty.EvaluatedValue); var isFrameworkAssembly = IsFrameworkAssembly(assemblyName); if (!isFrameworkAssembly) { projectInfo.GeneratedAssembly = assemblyName; projectInfo.ProjectGuid = projectGuid; } if (Verbose) Console.WriteLine(assemblyName); var references = from item in project.Items where item.ItemType == "Reference" select item; foreach (var reference in references) { var include = reference.EvaluatedInclude; var includeAssemblyName = include.Split(',')[0]; var isIncludeFrameworkAssembly = IsFrameworkAssembly(includeAssemblyName); if (!isFrameworkAssembly && !isIncludeFrameworkAssembly) { if (Verbose) Console.WriteLine("\tReferences {0}", includeAssemblyName); projectInfo.ReferencedAssemblies.Add(includeAssemblyName); } ProcessInclude(projectInfo, include); } } else { Console.WriteLine("\t has no project GUID!"); } var projectReferences = from item in project.Items where item.ItemType == "ProjectReference" select item; foreach (var projectReference in projectReferences) { if (Verbose) Console.WriteLine("\t references project '{0}'", projectReference); var referenceGuid = projectReference.DirectMetadata.FirstOrDefault(x => x.Name == "Project"); if (referenceGuid != null) projectInfo.ReferencedProjects.Add(new Guid(referenceGuid.EvaluatedValue)); else Console.WriteLine("\t has no project GUID!"); } } } } catch (Exception ex) { Console.WriteLine("Could not process project '{0}'. {1}", projectFile, ex.Message); } if (Verbose) Console.WriteLine(); return projectInfo; }