Ejemplo n.º 1
0
        public override void Parse(VSSolutionFileParser parser)
        {
            while (true)
            {
                string line = parser.NextLine();

                if (line == null)
                {
                    parser.ThrowParserException("Unexpected end of solution file.");
                }

                Match endProjectMatch = VSSolution.RegexEndProject.Match(line);

                if (endProjectMatch.Success)
                {
                    break;
                }
            }
        }
Ejemplo n.º 2
0
        public override void Parse(VSSolutionFileParser parser)
        {
            string line = parser.NextLine().Trim();

            if (line == "EndProject")
            {
                return;
            }

            if (line != "ProjectSection(SolutionItems) = preProject")
            {
                parser.ThrowParserException("Unexpected token. 'ProjectSection' expected.");
            }

            while (true)
            {
                line = parser.NextLine().Trim();
                if (line == "EndProjectSection")
                {
                    break;
                }

                string[] splits = line.Split('=');
                if (splits.Length != 2)
                {
                    parser.ThrowParserException("Unexpected token.");
                }

                _files.Add(splits[0].Trim());
            }

            line = parser.NextLine().Trim();
            if (line != "EndProject")
            {
                parser.ThrowParserException("'EndProject' expected.");
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Loads the specified VisualStudio solution file and returns a <see cref="VSSolution"/> representing the solution.
        /// </summary>
        /// <param name="fileName">The name of the solution file.</param>
        /// <returns>A <see cref="VSSolution"/> representing the solution.</returns>
        public static VSSolution Load(string fileName)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                return(null);
            }

            fileName = fileName.Replace(@"\", "/");
            VSSolution solution = new VSSolution(fileName);

            using (Stream stream = File.Open(fileName, FileMode.Open, FileAccess.Read))
            {
                using (StreamReader reader = new StreamReader(stream))
                {
                    VSSolutionFileParser parser = new VSSolutionFileParser(reader);

                    string line = parser.NextLine();

                    Match solutionMatch = RegexSolutionVersion.Match(line);

                    if (solutionMatch.Success == false)
                    {
                        parser.ThrowParserException("Not a solution file.");
                    }

                    solution.SolutionVersion = decimal.Parse(
                        solutionMatch.Groups["version"].Value,
                        CultureInfo.InvariantCulture);

                    while (true)
                    {
                        line = parser.NextLine();

                        if (line == null)
                        {
                            break;
                        }

                        // exit the loop when 'Global' section appears
                        if (RegexGlobal.IsMatch(line))
                        {
                            break;
                        }

                        Match projectMatch = RegexProject.Match(line);

                        if (!projectMatch.Success)
                        {
                            // skip any solution properties
                            if (RegexSolutionProperty.IsMatch(line))
                            {
                                continue;
                            }

                            // if nothing matches, we have a problem
                            parser.ThrowParserException(
                                string.Format(
                                    CultureInfo.InvariantCulture,
                                    "Could not parse solution file (line {0}): '{1}'.",
                                    parser.LineCount,
                                    line));
                        }

                        Guid   projectGuid     = new Guid(projectMatch.Groups["projectGuid"].Value);
                        string projectName     = projectMatch.Groups["name"].Value;
                        string projectFileName = projectMatch.Groups["path"].Value;
                        Guid   projectTypeGuid = new Guid(projectMatch.Groups["projectTypeGuid"].Value);

                        VSProjectInfo project;
                        if (projectTypeGuid == VSProjectType.SolutionFolderProjectType.ProjectTypeGuid)
                        {
                            project = new VSSolutionFilesInfo(
                                solution,
                                projectGuid,
                                projectName,
                                projectTypeGuid);
                        }
                        else
                        {
                            project = new VSProjectWithFileInfo(
                                solution,
                                projectGuid,
                                projectName,
                                new LocalPath(projectFileName),
                                projectTypeGuid);
                        }

                        solution._projects.Add(project);
                        project.Parse(parser);
                    }
                }
            }

            return(solution);
        }
Ejemplo n.º 4
0
 public abstract void Parse(VSSolutionFileParser parser);