Esempio n. 1
0
 public static ProjectNode FindProject(SolutionNode solution, string projectName)
 {
     var projects = solution.DescendantNodes().OfType<ProjectNode>().ToList();
     var proj = projects.WithName(projectName);
     if(proj == null)
         throw new Exception($"Could not find project {projectName} among the following: {projects.Select(x => x.Name).ToDelimitedString()}");
     return proj;
 }
Esempio n. 2
0
        public void ContainsDependenciesFromDifferentProject()
        {
            var pidA = ProjectId.CreateNewId("A");
            var pidB = ProjectId.CreateNewId("B");
            var didA = DocumentId.CreateNewId(pidA);
            var didB = DocumentId.CreateNewId(pidB);

            const string docA = @"
            namespace A
            {
                public class Button {public void Bar(){}}
            }
            ";

            const string docB = @"
            namespace B
            {
                class GuiFacade
                {
                    public void Foo(){new A.Button().Bar();}
                    public static void Main(){}
                }
            }
            ";

            var solution = MSBuildWorkspace.Create(new Dictionary<string, string> { { "CheckForSystemRuntimeDependency", "true" } }).CurrentSolution
            .AddProject(pidA, "ProjectA", "A.dll", LanguageNames.CSharp)
            .AddDocument(didA, "A.cs", docA)
            .AddProject(pidB, "ProjectB", "B.dll", LanguageNames.CSharp)
            .AddDocument(didB, "B.cs", docB)
            .AddProjectReference(pidB, new ProjectReference(pidA));

            var tree = new SolutionNode();
            tree.AddChild(new ProjectNode {Documents = solution.GetProject(pidA).Documents });
            tree.AddChild(new ProjectNode { Documents = solution.GetProject(pidB).Documents });
            ClassTreeBuilder.AddClassesInProjectsToTree(tree);
            var button = tree.DescendantNodes().WithName("Button") as ClassNode;
            var guiFacade = tree.DescendantNodes().WithName("GuiFacade");
            button.Should().NotBeNull();
            guiFacade.Should().NotBeNull();
            guiFacade.Dependencies.Should().NotBeEmpty();
        }
Esempio n. 3
0
        /*public static void AddDocumentsToProjects(Solution solution, ref SolutionNode tree)
        {
            var allreadyAddedProjects = tree.DescendantNodes().OfType<ProjectNode>().ToList();
            foreach (var project in allreadyAddedProjects)
            {
                project.Documents = solution.GetProject(ProjectId.CreateFromSerialized(project.ProjectId)).Documents.ToList();
            }
        }*/
        public static void AddDocumentsToProjects(Solution solution, ref SolutionNode tree)
        {
            var projects = solution.Projects.ToList();
            var allreadyAddedProjects = tree.DescendantNodes().OfType<ProjectNode>().ToList();

            foreach (var project in projects)
            {
                var existingProject = allreadyAddedProjects.WithName(project.Name);
                if (existingProject != null)
                {
                    existingProject.Documents = project.Documents.ToList();
                }
                else
                    throw new Exception($@"Project '{project.Name}' found by roslyn was not found by EnvDte or MSBuild");
            }
        }
Esempio n. 4
0
        public static void AddClassesInProjectsToTree(SolutionNode tree)
        {
            var projects = tree.DescendantNodes().OfType<ProjectNode>().ToList();
            var allClasses = new List<ClassNode>();

            foreach (var project in projects)
            {
                var documents = project.Documents.ToList();
                if (!documents.Any()) continue;

                var semanticModels = documents.SelectList(d => d.GetSemanticModelAsync().Result);
                var classes = SemanticModelWalker.GetClassesInModels(semanticModels);
                if (!classes.Any())
                    continue;
                allClasses.AddRange(classes);
                var classnodes = BuildTreeFromClasses(classes);
                project.AddChilds(classnodes);
            }

            DependencyResolver.ResolveDependencies(allClasses);
        }