public bool RegisterSection(ProjectSection projectSection)
        {
            if (projectSection == null)
            {
                return(false);
            }

            string projectGuid = projectSection.ProjectGuid;

            if (String.IsNullOrEmpty(projectGuid) ||
                _projectSections.ContainsKey(projectGuid))
            {
                return(false);
            }

            _projectSections.Add(projectGuid, projectSection);

            // If a corresponding project information is not registered, we
            // register it...
            if (!_projectInfo.ContainsKey(projectGuid))
            {
                ProjectInfo info = new ProjectInfo(projectSection.ProjectFile,
                                                   projectGuid, projectSection.ProjectName);
                if (info.IsValid)
                {
                    _projectInfo.Add(projectGuid, info);
                }
            }

            return(true);
        }
Exemple #2
0
        public void AddChild(ProjectSection section)
        {
            if (section != null)
            {
                _children.Add(section);

                if (_context != null)
                {
                    _context.RegisterSection(section);
                }
            }
        }
        public static ProjectSection CreateSection(ProjectSectionContext context,
                                                   string projectFile)
        {
            if (String.IsNullOrEmpty(projectFile))
            {
                return(null);
            }
            projectFile = Path.GetFullPath(
                Environment.ExpandEnvironmentVariables(projectFile));

            string fileExt = Path.GetExtension(projectFile);

            if (String.IsNullOrEmpty(fileExt))
            {
                return(null);
            }

            ProjectSection projectSection = null;

            switch (fileExt.ToLower())
            {
            case ".csproj":
            case ".vbproj":
            case ".fsproj":
            case ".pyproj":
            case ".rbproj":
            case ".vjsproj":
                projectSection = new StandardProjectSection();
                projectSection.Parse(context, projectFile);
                break;

            case ".vcproj":
                // For the Visual C++ project, these are required...
                RequiresAll(context.SolutionFile, context.Platform,
                            context.Configuration);

                projectSection = new VcProjectSection();
                projectSection.Parse(context, projectFile);
                break;

            case ".vcxproj":
                // For the Visual C++ project, these are required...
                RequiresAll(context.SolutionFile, context.Platform,
                            context.Configuration);

                projectSection = new VcxProjectSection();
                projectSection.Parse(context, projectFile);
                break;
            }

            return(projectSection);
        }
        public static ProjectSection CreateSection(ProjectSectionContext context,
                                                   ProjectInfo projectInfo)
        {
            if (context != null)
            {
                ProjectSection projectSection = context.GetProjectSection(
                    projectInfo.ProjectGuid);

                if (projectSection != null)
                {
                    return(projectSection);
                }
            }

            return(CreateSection(context, projectInfo.ProjectPath));
        }
Exemple #5
0
        protected virtual void CreateChildren(IList <ProjectInfo> referenceProjects)
        {
            if (_context == null)
            {
                throw new InvalidOperationException(
                          "There is no project section context attached to this project.");
            }

            if (referenceProjects == null || referenceProjects.Count == 0)
            {
                return;
            }

            for (int i = 0; i < referenceProjects.Count; i++)
            {
                ProjectInfo referenceProject = referenceProjects[i];
                if (referenceProject == null || !referenceProject.IsValid)
                {
                    continue;
                }

                // First search the registered projects to avoid duplications
                ProjectSection childSection = _context.GetProjectSection(
                    referenceProject.ProjectGuid);
                if (childSection == null)
                {
                    childSection = ProjectSectionFactory.CreateSection(
                        _context, referenceProject.ProjectPath);
                }

                if (childSection != null)
                {
                    this.AddChild(childSection);
                }
            }
        }
        public static IList <ProjectSection> CreateSections(string sourceFile,
                                                            string platform, string configuration, HashSet <string> targetProjectGuids)
        {
            sourceFile = Path.GetFullPath(
                Environment.ExpandEnvironmentVariables(sourceFile));

            string fileExt = Path.GetExtension(sourceFile);

            if (String.IsNullOrEmpty(fileExt))
            {
                return(null);
            }

            ProjectSectionContext context = new ProjectSectionContext();

            context.Platform      = platform;
            context.Configuration = configuration;

            if (targetProjectGuids != null && targetProjectGuids.Count != 0)
            {
                context.RegisterTargets(targetProjectGuids);
            }

            List <ProjectSection> projectSections = new List <ProjectSection>();

            if (fileExt.Equals(".sln", StringComparison.OrdinalIgnoreCase))
            {
                context.SolutionFile = sourceFile;

                IList <ProjectInfo> listProjectInfo = GetProjectInfo(sourceFile);

                if (listProjectInfo != null && listProjectInfo.Count != 0)
                {
                    // Register projects for reference resolution...
                    context.RegisterInfo(listProjectInfo);

                    // If we are documenting all, then add the targets...
                    if (targetProjectGuids == null || targetProjectGuids.Count == 0)
                    {
                        for (int i = 0; i < listProjectInfo.Count; i++)
                        {
                            ProjectInfo projectInfo = listProjectInfo[i];

                            if (projectInfo != null && projectInfo.IsValid)
                            {
                                context.RegisterTarget(projectInfo.ProjectGuid);
                            }
                        }
                    }

                    for (int i = 0; i < listProjectInfo.Count; i++)
                    {
                        ProjectInfo projectInfo = listProjectInfo[i];

                        if (projectInfo != null && projectInfo.IsValid &&
                            context.IsTarget(projectInfo.ProjectGuid))
                        {
                            ProjectSection projectSection = context.GetProjectSection(
                                projectInfo.ProjectGuid);
                            if (projectSection == null)
                            {
                                projectSection = CreateSection(context, projectInfo);
                            }

                            if (projectSection != null)
                            {
                                projectSections.Add(projectSection);
                                context.RegisterSection(projectSection);
                            }
                        }
                    }
                }
            }
            else
            {
                ProjectSection projectSection = CreateSection(context, sourceFile);

                if (projectSection != null)
                {
                    projectSections.Add(projectSection);
                    context.RegisterSection(projectSection);
                }
            }

            return(projectSections);
        }