Example #1
0
        Microsoft.Build.BuildEngine.Project GetMSBuildProject(NPanday.ProjectImporter.Parser.SlnParser.Model.Solution solution, string projectGuid)
        {
            foreach (NPanday.ProjectImporter.Parser.SlnParser.Model.Project p in solution.Projects)
            {
                if (p.ProjectGUID.Equals("{" + projectGuid + "}", StringComparison.OrdinalIgnoreCase))
                {
                    string projectReferenceName     = p.ProjectName;
                    string projectReferencePath     = p.ProjectPath;
                    string projectReferenceFullPath = null;

                    if (Path.IsPathRooted(projectReferencePath))
                    {
                        projectReferenceFullPath = Path.GetFullPath(projectReferencePath);
                    }
                    else
                    {
                        projectReferenceFullPath = Path.Combine(solution.File.Directory.FullName, projectReferencePath);
                    }


                    Microsoft.Build.BuildEngine.Project prj = new Microsoft.Build.BuildEngine.Project(BUILD_ENGINE);
                    prj.Load(projectReferenceFullPath);

                    return(prj);
                }
            }

            return(null);
        }
Example #2
0
        Microsoft.Build.BuildEngine.Project GetMSBuildProject(NPanday.ProjectImporter.Parser.SlnParser.Model.Solution solution, string projectGuid)
        {
            foreach (NPanday.ProjectImporter.Parser.SlnParser.Model.Project p in solution.Projects)
            {
                if (p.ProjectGUID.Equals("{" + projectGuid + "}", StringComparison.OrdinalIgnoreCase))
                {
                    string projectReferenceName     = p.ProjectName;
                    string projectReferencePath     = p.ProjectPath;
                    string projectReferenceFullPath = null;

                    if (Path.IsPathRooted(projectReferencePath))
                    {
                        projectReferenceFullPath = Path.GetFullPath(projectReferencePath);
                    }
                    else
                    {
                        projectReferenceFullPath = Path.Combine(solution.File.Directory.FullName, projectReferencePath);
                    }


                    Microsoft.Build.BuildEngine.Project prj = new Microsoft.Build.BuildEngine.Project(BUILD_ENGINE);

                    try
                    {
                        // TODO: if we update to a .NET 3.5 minimum we can pass in ProjectLoadSettings.IgnoreMissingImports
                        prj.Load(projectReferenceFullPath);
                    }
                    catch (Exception e)
                    {
                        log.Error("Unable to load project reference from " + projectReferenceFullPath, e);
                    }

                    return(prj);
                }
            }

            return(null);
        }
Example #3
0
        public static Solution GetSolution(FileInfo solutionFile)
        {
            LexicalAnalizer lexan = new LexicalAnalizer(solutionFile);
            Solution solution = new Solution();
            solution.File = solutionFile;

            lexan.MoveNext();

            while(lexan.Current.Token == Semantics.EOL)
            {
                // some sln files contains blank lines before the header values, so its best to recourse it first
                lexan.Expect(Semantics.EOL);
                lexan.MoveNext();
            }

            lexan.Expect(Semantics.STRING_VALUE);
            solution.Header = lexan.Current.Value;
            lexan.MoveNext();

            lexan.Expect(Semantics.COMMA);
            lexan.MoveNext();

            lexan.Expect(Semantics.STRING_VALUE);
            solution.FormatVersion = lexan.Current.Value;
            lexan.MoveNext();

            lexan.Expect(Semantics.EOL);
            lexan.MoveNext();

            lexan.Expect(Semantics.STRING_VALUE);
            solution.VsVersion = lexan.Current.Value;
            lexan.MoveNext();

            lexan.Expect(Semantics.EOL);

            while (lexan.MoveNext())
            {
                switch (lexan.Current.Token)
                {
                    case Semantics.PROJECT:
                        solution.Projects.Add(GetProject(lexan));
                        break;
                    case Semantics.GLOBAL:
                        solution.Globals.Add(GetGlobal(lexan));
                        break;
                    case Semantics.EOL:
                        break;
                    case Semantics.STRING_VALUE:
                        if (lexan.Current.Value.Trim().Equals("VisualStudioVersion"))
                        {
                            solution.VisualStudioVersion = GetProperty(lexan);
                        }
                        else if (lexan.Current.Value.Trim().Equals("MinimumVisualStudioVersion"))
                        {
                            solution.MinimumVisualStudioVersion = GetProperty(lexan);
                        }
                        break;
                    default:
                        throw new Exception("Unknown Solution token: " + lexan.Current.Token);
                }
            }

            return solution;
        }
Example #4
0
        protected void ParseProjectReferences(Dictionary <string, object> dictionary, NPanday.ProjectImporter.Parser.SlnParser.Model.Project project, NPanday.ProjectImporter.Parser.SlnParser.Model.Solution solution)
        {
            if (project.ProjectSections != null)
            {
                List <Microsoft.Build.BuildEngine.Project> projectReferenceList = new List <Microsoft.Build.BuildEngine.Project>();
                foreach (ProjectSection ps in project.ProjectSections)
                {
                    if ("WebsiteProperties".Equals(ps.Name))
                    {
                        // ProjectReferences = "{11F2FCC8-5941-418A-A0E7-42D250BA9D21}|SampleInterProject111.dll;{9F37BA7B-06F9-4B05-925D-B5BC16322E8B}|BongClassLib.dll;"

                        try
                        {
                            Regex           regex   = new Regex(PROJECT_REFERENCE_REGEX, RegexOptions.Multiline | RegexOptions.IgnoreCase);
                            MatchCollection matches = regex.Matches(ps.Map["ProjectReferences"]);


                            foreach (Match match in matches)
                            {
                                string projectReferenceGUID = match.Groups["ProjectReferenceGUID"].ToString();
                                string projectReferenceDll  = match.Groups["ProjectReferenceDll"].ToString();

                                Microsoft.Build.BuildEngine.Project prj = GetMSBuildProject(solution, projectReferenceGUID);
                                if (prj != null)
                                {
                                    projectReferenceList.Add(prj);
                                }
                            }
                        }
                        catch { }
                    }
                    else if ("ProjectDependencies".Equals(ps.Name))
                    {
                        //{0D80BE11-F1CE-409E-B9AC-039D3801209F} = {0D80BE11-F1CE-409E-B9AC-039D3801209F}

                        foreach (string key in ps.Map.Keys)
                        {
                            Microsoft.Build.BuildEngine.Project prj = GetMSBuildProject(solution, key.Replace("{", "").Replace("}", ""));
                            if (prj != null)
                            {
                                projectReferenceList.Add(prj);
                            }
                        }
                    }
                }

                dictionary.Add("InterProjectReferences", projectReferenceList.ToArray());
            }
        }