Exemple #1
0
 /// <summary>
 /// Loads the VisualStudio project files and fills the project data into <see cref="VSProject.ProjectDetails"/>
 /// properties for each of the project in the solution.
 /// </summary>
 protected internal void LoadProjects()
 {
     ForEachProject(projectInfo =>
     {
         if (projectInfo.ProjectTypeGuid == VSProjectType.CSharpProjectType.ProjectTypeGuid || projectInfo.ProjectTypeGuid == VSProjectType.NewCSharpProjectType.ProjectTypeGuid)
         {
             ((VSProject)projectInfo).ProjectDetails = VSProjectDetails.Load(((VSProject)projectInfo).ProjectFileNameFull.ToString());
         }
     });
 }
        /// <summary>
        /// Loads the specified project file name.
        /// </summary>
        /// <param name="projectFileName">Name of the project file.</param>
        /// <returns>VSProject class containing project information.</returns>
        public static VSProjectDetails Load(string projectFileName)
        {
            projectFileName = projectFileName.Replace(@"\", "/");
            using (Stream stream = File.OpenRead(projectFileName))
            {
                VSProjectDetails data = new VSProjectDetails {
                    _propertiesDictionary = true
                };

                XmlReaderSettings xmlReaderSettings = new XmlReaderSettings
                {
                    IgnoreComments = true,
                    IgnoreProcessingInstructions = true,
                    IgnoreWhitespace             = true
                };

                using (XmlReader xmlReader = XmlReader.Create(stream, xmlReaderSettings))
                {
                    xmlReader.Read();
                    while (!xmlReader.EOF)
                    {
                        switch (xmlReader.NodeType)
                        {
                        case XmlNodeType.XmlDeclaration:
                            xmlReader.Read();
                            break;

                        case XmlNodeType.Element:
                            if (xmlReader.Name == "Project")
                            {
                                data.ReadProject(projectFileName, xmlReader);
                            }

                            xmlReader.Read();
                            break;

                        default:
                            xmlReader.Read();
                            continue;
                        }
                    }
                }

                return(data);
            }
        }