Example #1
0
 public VSSolutionFilesInfo(
     VSSolution ownerSolution,
     Guid projectGuid,
     string projectName,
     Guid projectTypeGuid)
     : base(ownerSolution, projectGuid, projectName, projectTypeGuid)
 {
 }
Example #2
0
 public VSProjectWithFileInfo(
     VSSolution ownerSolution,
     Guid projectGuid,
     string projectName,
     LocalPath projectFileName,
     Guid projectTypeGuid) : base(ownerSolution, projectGuid, projectName, projectTypeGuid)
 {
     this.projectFileName = projectFileName;
 }
Example #3
0
 protected VSProjectInfo(
     VSSolution ownerSolution,
     Guid projectGuid,
     string projectName,
     Guid projectTypeGuid)
 {
     this.ownerSolution   = ownerSolution;
     this.projectTypeGuid = projectTypeGuid;
     this.projectName     = projectName;
     this.projectGuid     = projectGuid;
 }
Example #4
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)
        {
            Log.DebugFormat("Load ('{0}')", fileName);

            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
                        Match globalMatch = RegexGlobal.Match(line);
                        if (globalMatch.Success)
                        {
                            break;
                        }

                        Match projectMatch = RegexProject.Match(line);

                        if (projectMatch.Success == false)
                        {
                            parser.ThrowParserException(
                                String.Format(
                                    CultureInfo.InvariantCulture,
                                    "Could not parse solution file (line {0}).",
                                    parser.LineCount));
                        }

                        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,
                                projectFileName,
                                projectTypeGuid);
                        }

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

            return(solution);
        }