public SolutionInfo(BuildDefinitionInfo buildDefinitionInfo, string name) { this.Name = name; this.ReferencedAssemblies = new HashSet<string>(); this.BuildDefinition = buildDefinitionInfo; this.DependentSolutions = new List<SolutionInfo>(); this.Projects = new List<ProjectInfo>(); }
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 SolutionInfo ProcessSolution(BuildDefinitionInfo buildDefinitionInfo, string solutionFile) { if (Verbose) Console.WriteLine("Solution: '{0}'", solutionFile); var solutionInfo = new SolutionInfo(buildDefinitionInfo, solutionFile); try { using (var solutionFileStream = ReadFileFromVersionControlServer(buildDefinitionInfo.TeamCollection.Collection, solutionFile)) { using (StreamReader reader = new StreamReader(solutionFileStream)) { var solutionParser = new Solution(reader); var projects = solutionParser.Projects; foreach (var solutionProject in projects) { if (solutionProject.ProjectType == "SolutionFolder" || Regex.Match(solutionProject.ProjectName, "Test", RegexOptions.IgnoreCase).Success) continue; var projectDir = Path.GetDirectoryName(solutionFile); if (projectDir == null) continue; var fullPath = Path.Combine(projectDir, solutionProject.RelativePath); var projectFile = fullPath.Replace('\\', '/'); var projectAssembliesInfo = ProcessProject(solutionInfo, projectFile); solutionInfo.Projects.Add(projectAssembliesInfo); solutionInfo.ReferencedAssemblies.UnionWith(projectAssembliesInfo.ReferencedAssemblies); } } } // if there are references between projects, add them also foreach (var project in solutionInfo.Projects) { foreach (var referencedProject in project.ReferencedProjects) { var referenceMatches = solutionInfo[referencedProject]; if (referenceMatches != null) { project.ReferencedAssemblies.Add(referenceMatches.GeneratedAssembly); solutionInfo.ReferencedAssemblies.UnionWith(project.ReferencedAssemblies); } } } } catch (Exception ex) { Console.WriteLine("Could not process solution '{0}'. {1}", solutionFile, ex.Message); } if (Verbose) Console.WriteLine(); return solutionInfo; }
private BuildDefinitionInfo ProcessBuildDefinition(TeamCollectionInfo teamCollectionInfo, IBuildDefinition buildDefinition) { if (Verbose) Console.WriteLine($"Build definition: '{buildDefinition.Name}'"); var buildDefinitionInfo = new BuildDefinitionInfo(teamCollectionInfo, buildDefinition); try { var paramValues = WorkflowHelpers.DeserializeProcessParameters(buildDefinition.ProcessParameters); //if (!paramValues.ContainsKey(SharedAssembliesParamName)) continue; //var sharedAssemblies = (string)paramValues[SharedAssembliesParamName]; if (!paramValues.ContainsKey(Constants.ProjectsToBuildParamName)) Console.WriteLine("Build definition '{0}' does not compile any project.", buildDefinition.Name); else { var solutionFiles = (string[])paramValues[Constants.ProjectsToBuildParamName]; foreach (var solutionFile in solutionFiles.Where(x => x.EndsWith(".sln"))) { var assembliesInfo = ProcessSolution(buildDefinitionInfo, solutionFile); buildDefinitionInfo.Solutions.Add(assembliesInfo); buildDefinitionInfo.ReferencedAssemblies.UnionWith(assembliesInfo.ReferencedAssemblies); } } } catch (Exception ex) { Console.WriteLine("Could not process build definition '{0}'. {1}", buildDefinition.Name, ex.Message); } if (Verbose) Console.WriteLine(); return buildDefinitionInfo; }