public static ProjectSection CreateSection(string projectFile,
                                                   string solutionFile, string platform, string configuration)
        {
            ProjectSectionContext context = new ProjectSectionContext();

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

            if (String.IsNullOrEmpty(projectFile))
            {
                return(null);
            }
            projectFile = Path.GetFullPath(
                Environment.ExpandEnvironmentVariables(projectFile));

            string fileExt = Path.GetExtension(projectFile);

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

            return(CreateSection(context, projectFile));
        }
Esempio n. 2
0
        public virtual bool Parse(ProjectSectionContext context, string projectFile)
        {
            _context = context;

            _projectFile = Path.GetFullPath(
                Environment.ExpandEnvironmentVariables(projectFile));

            // Extract the project directory for the resolution of the relative paths...
            string projectDir = Path.GetDirectoryName(_projectFile);

            if (!projectDir.EndsWith("\\", StringComparison.Ordinal))
            {
                projectDir += "\\";
            }

            _projectDir = projectDir;

            // Reset all the current properties...
            _platform                  = String.Empty;
            _outputType                = String.Empty;
            _outputPath                = String.Empty;
            _outputFile                = String.Empty;
            _commentFile               = String.Empty;
            _assemblyName              = String.Empty;
            _configuration             = String.Empty;
            _targetFrameworkVersion    = String.Empty;
            _targetFrameworkIdentifier = String.Empty;

            _referencedAssemblies      = new List <string>();
            _referencedPaths           = new List <string>();
            _referencedKnownAssemblies = new List <string>();

            return(true);
        }
        public override bool Parse(ProjectSectionContext context, string projectFile)
        {
            if (!base.Parse(context, projectFile))
            {
                return(false);
            }

            // Open the project for parsing...
            _project = ProjectRootElement.Open(this.ProjectFile, new ProjectCollection());

            return(_project != null);
        }
        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));
        }
Esempio n. 6
0
        public override bool Parse(ProjectSectionContext context, string projectFile)
        {
            _standardType = StandardProjectType.None;

            if (!base.Parse(context, projectFile))
            {
                return(false);
            }

            _standardType = ProjectSectionFactory.GetStandardType(projectFile);

            bool isSuccessful = this.ParseProperties();

            if (!isSuccessful)
            {
                // If not successful, we try parsing "Choose" elements, since the ff.
                // is equally valid as conditioned property group....

                //<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
                //    <PropertyGroup>
                //        <Configuration Condition="'$(Configuration)' == ''">Debug</Configuration>
                //        <OutputType>Exe</OutputType>
                //        <RootNamespace>Application1</RootNamespace>
                //        <AssemblyName>Application1</AssemblyName>
                //        <WarningLevel>4</WarningLevel>
                //    </PropertyGroup>
                //    <Choose>
                //        <When Condition=" '$(Configuration)'=='debug' ">
                //            <PropertyGroup>
                //                <OutputPath>.\bin\Debug\</OutputPath>
                //            </PropertyGroup>
                //        </When>
                //        <When Condition=" '$(Configuration)'=='retail' ">
                //            <PropertyGroup>
                //                <OutputPath>.\bin\Release\</OutputPath>
                //            </PropertyGroup>
                //        </When>
                //        <Otherwise>
                //            <PropertyGroup>
                //                <OutputPath>.\bin\$(Configuration)\</OutputPath>
                //            </PropertyGroup>
                //        </Otherwise>
                //    </Choose>
                //</Project>

                isSuccessful = this.ParseChoose();
            }

            if (!isSuccessful)
            {
                return(isSuccessful);
            }

            List <ProjectInfo> referencedProjects = new List <ProjectInfo>();

            isSuccessful = this.ParseReferenceItems(referencedProjects);

            this.CreateChildren(referencedProjects);

            return(isSuccessful);
        }
        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);
        }
Esempio n. 8
0
        public override bool Parse(ProjectSectionContext context, string projectFile)
        {
            if (!base.Parse(context, projectFile))
            {
                return(false);
            }

            // The platform and configuration information are provided by the
            // user for the Visual C++ projects...
            this.Platform      = context.ActivePlatform;
            this.Configuration = context.ActiveConfiguration;

            bool isSuccessful = this.ValidateConfigurations();

            if (!isSuccessful)
            {
                return(false);
            }

            isSuccessful = this.ParseProperties();
            if (!isSuccessful)
            {
                // If not successful, we try parsing "Choose" elements, since the ff.
                // is equally valid as conditioned property group....

                //<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
                //    <PropertyGroup>
                //        <Configuration Condition="'$(Configuration)' == ''">Debug</Configuration>
                //        <OutputType>Exe</OutputType>
                //        <RootNamespace>Application1</RootNamespace>
                //        <AssemblyName>Application1</AssemblyName>
                //        <WarningLevel>4</WarningLevel>
                //    </PropertyGroup>
                //    <Choose>
                //        <When Condition=" '$(Configuration)'=='debug' ">
                //            <PropertyGroup>
                //                <OutputPath>.\bin\Debug\</OutputPath>
                //            </PropertyGroup>
                //        </When>
                //        <When Condition=" '$(Configuration)'=='retail' ">
                //            <PropertyGroup>
                //                <OutputPath>.\bin\Release\</OutputPath>
                //            </PropertyGroup>
                //        </When>
                //        <Otherwise>
                //            <PropertyGroup>
                //                <OutputPath>.\bin\$(Configuration)\</OutputPath>
                //            </PropertyGroup>
                //        </Otherwise>
                //    </Choose>
                //</Project>

                isSuccessful = this.ParseChoose();
            }

            if (!isSuccessful)
            {
                isSuccessful = this.ParseDefaults();
            }

            if (!isSuccessful)
            {
                return(isSuccessful);
            }

            List <ProjectInfo> referencedProjects = new List <ProjectInfo>();

            isSuccessful = this.ParseReferenceItems(referencedProjects);

            this.CreateChildren(referencedProjects);

            return(isSuccessful);
        }
Esempio n. 9
0
        private bool ParseDefaults()
        {
            if (!String.IsNullOrEmpty(this.OutputFile) &&
                File.Exists(this.OutputFile))
            {
                // Possibility: The documentation file is explicitly defined

                //<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
                //  <ClCompile/>
                //  </ClCompile>
                //  <Link/>
                //  <Xdcmake>
                //    <OutputFile>Debug\TestingCPP3.xml</OutputFile>
                //  </Xdcmake>
                //</ItemDefinitionGroup>

                ICollection <ProjectItemDefinitionGroupElement> itemDefGroups =
                    this.Project.ItemDefinitionGroups;

                foreach (ProjectItemDefinitionGroupElement itemDefGroup
                         in itemDefGroups)
                {
                    if (IsConditionMatched(this.Configuration, this.Platform,
                                           itemDefGroup.Condition))
                    {
                        bool isFound = false;

                        foreach (ProjectItemDefinitionElement itemDef
                                 in itemDefGroup.ItemDefinitions)
                        {
                            if (String.Equals(itemDef.ItemType, "Xdcmake",
                                              StringComparison.OrdinalIgnoreCase))
                            {
                                foreach (ProjectMetadataElement metadata
                                         in itemDef.Metadata)
                                {
                                    if (!String.Equals(metadata.Name, "OutputFile",
                                                       StringComparison.OrdinalIgnoreCase))
                                    {
                                        continue;
                                    }

                                    string tempValue = metadata.Value;
                                    if (String.IsNullOrEmpty(tempValue))
                                    {
                                        continue;
                                    }
                                    tempValue = this.EvaluateMacros(tempValue);

                                    if (Path.IsPathRooted(tempValue))
                                    {
                                        this.CommentFile = Path.GetFullPath(tempValue);
                                    }
                                    else
                                    {
                                        this.CommentFile = Path.GetFullPath(
                                            Path.Combine(this.ProjectDir, tempValue));
                                    }

                                    isFound = true;
                                    break;
                                }
                            }

                            if (isFound)
                            {
                                break;
                            }
                        }
                    }
                }
            }
            else
            {
                // Possibility: Default output directories are used...
                // $(SolutionDir)$(Configuration)\$(ProjectName)

                ProjectSectionContext context = this.Context;
                string workingDir             = Path.Combine(context.SolutionDir,
                                                             this.Configuration);

                if (Directory.Exists(workingDir))
                {
                    if (String.IsNullOrEmpty(this.OutputPath))
                    {
                        this.OutputPath = workingDir;
                    }

                    switch (this.OutputType.ToLower())
                    {
                    case "library":
                    case "dynamiclibrary":
                        this.OutputFile = Path.GetFullPath(Path.Combine(
                                                               workingDir, this.AssemblyName + ".dll"));
                        break;

                    case "exe":
                    case "application":
                        this.OutputFile = Path.GetFullPath(Path.Combine(
                                                               workingDir, this.AssemblyName + ".exe"));
                        break;
                    }

                    if (String.IsNullOrEmpty(this.CommentFile) || !File.Exists(this.CommentFile))
                    {
                        this.CommentFile = Path.GetFullPath(Path.Combine(
                                                                workingDir, this.AssemblyName + ".xml"));
                    }
                }
            }

            //if (this.IsTarget)
            //{
            //    // It is an referenced project and is normally used as dependency.
            //    // For this, only the assembly file is required...
            //    return (!String.IsNullOrEmpty(this.OutputFile) && File.Exists(this.OutputFile));
            //}
            //else
            //{
            //    // It is an outer project, and must have both assembly and comment
            //    // to be valid...
            //    return ((!String.IsNullOrEmpty(this.OutputFile) && File.Exists(this.OutputFile))
            //        && (!String.IsNullOrEmpty(this.CommentFile) && File.Exists(this.CommentFile)));
            //}

            return(!String.IsNullOrEmpty(this.OutputFile) && File.Exists(this.OutputFile));
        }
Esempio n. 10
0
        public override bool Parse(ProjectSectionContext context, string projectFile)
        {
            if (!base.Parse(context, projectFile))
            {
                return(false);
            }

            // The platform and configuration information are provided by the
            // user for the Visual C++ projects...
            this.Platform      = context.ActivePlatform;
            this.Configuration = context.ActiveConfiguration;

            // Open the project for parsing...
            _project = VcProjectRootElement.Open(projectFile);
            if (_project == null)
            {
                return(false);
            }

            _version = new Version(_project.Version);

            string tempText = _project.TargetFrameworkVersion;

            if (String.IsNullOrEmpty(tempText))
            {
                // Project files for VC++ 2003/2005 do not have the TargetFrameworkVersion
                // attribute, so we use the project version information...
                switch (_version.Major)
                {
                case 8:     // VS.NET 2005 and supports only .NET 2.0
                    this.TargetFrameworkVersion = "v2.0";
                    break;

                case 7:                                            // VS.NET 2002 or 2003 and support .NET 1.0 or 1.1
                    this.TargetFrameworkVersion = (_version.Minor == 1) ?
                                                  "v1.1" : "v1.0"; // VC++ 2002 is not yet tested
                    break;

                default:
                    throw new InvalidDataException(String.Format(
                                                       "The target framework version '{0}' is not known.", tempText));
                }
            }
            else
            {
                //TODO: Still could not find any reference for these version
                //      numbers, using the known values...
                switch (tempText.Trim())
                {
                case "196613":
                    this.TargetFrameworkVersion = "v3.5";
                    break;

                case "196608":
                    this.TargetFrameworkVersion = "v3.0";
                    break;

                case "131072":
                    this.TargetFrameworkVersion = "v2.0";
                    break;

                default:
                    throw new InvalidDataException(String.Format(
                                                       "The target framework version '{0}' is not known.", tempText));
                }
            }

            string targetIdentifer = _project["Keyword"];

            if (String.Equals(targetIdentifer, "ManagedCProj",
                              StringComparison.OrdinalIgnoreCase))
            {
                this.TargetFrameworkIdentifier = ".NETFramework";
            }
            else
            {
                this.TargetFrameworkIdentifier = targetIdentifer;
            }
            this.ProjectName = _project.Name;
            this.ProjectGuid = _project.ProjectGUID;

            bool isSuccessful = this.ValidatePlatforms();

            if (!isSuccessful)
            {
                throw new InvalidOperationException(
                          "The specified platform is not available.");
            }

            isSuccessful = this.ParseConfigurations();

            if (!isSuccessful)
            {
                return(isSuccessful);
            }

            List <ProjectInfo> referencedProjects = new List <ProjectInfo>();

            isSuccessful = this.ParseReferenceItems(referencedProjects);

            this.CreateChildren(referencedProjects);

            return(isSuccessful);
        }