Ejemplo n.º 1
0
        private void CalculateTargetGraph(Project project)
        {
            ProjectInstance projectInstance;

            if (!_projectToProjectInstanceMap.TryGetValue(project, out projectInstance))
            {
                // if for some reason we weren't able to fish out the project instance from MSBuild,
                // just add all orphans directly to the project
                var unparented = project.GetUnparentedTargets();
                foreach (var orphan in unparented)
                {
                    project.AddChild(orphan);
                }

                return;
            }

            var targetGraph = new TargetGraph(projectInstance);

            var unparentedTargets = project.GetUnparentedTargets();

            foreach (var unparentedTarget in unparentedTargets)
            {
                var parent = targetGraph.GetDependent(unparentedTarget.Name);
                if (parent != null)
                {
                    var parentNode = project.GetOrAddTargetByName(parent);
                    if (parentNode != null)
                    {
                        parentNode.AddChild(unparentedTarget);
                    }
                }

                if (unparentedTarget.Parent == null)
                {
                    project.AddChild(unparentedTarget);
                }
            }

            project.VisitAllChildren <Target>(t =>
            {
                if (t.Project == project)
                {
                    var dependencies = targetGraph.GetDependencies(t.Name);
                    if (dependencies != null && dependencies.Any())
                    {
                        t.DependsOnTargets = stringTable.Intern(string.Join(",", dependencies));
                    }
                }
            });
        }
Ejemplo n.º 2
0
        public void ProjectStarted(object sender, ProjectStartedEventArgs args)
        {
            try
            {
                lock (syncLock)
                {
                    Project parent = null;

                    int parentProjectId = args?.ParentProjectBuildEventContext.ProjectContextId ?? -1;
                    if (parentProjectId > 0)
                    {
                        parent = GetOrAddProject(parentProjectId);
                    }

                    var project = GetOrAddProject(args.BuildEventContext.ProjectContextId, args, parent);

                    if (parent != null)
                    {
                        parent.AddChild(project);
                    }
                    else
                    {
                        // This is a "Root" project (no parent project).
                        Build.AddChild(project);
                    }
                }
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }
        }