예제 #1
0
 public ProjectInfo(SolutionInfo solutionInfo)
 {
     this.ReferencedAssemblies = new HashSet<string>();
     this.ReferencedProjects = new HashSet<Guid>();
     this.DependentProjects = new List<ProjectInfo>();
     this.Solution = solutionInfo;
 }
예제 #2
0
        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);
        }
예제 #3
0
        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;
        }
예제 #4
0
        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;
        }