示例#1
0
        public List <Dictionary <string, object> > Parse(FileInfo solutionFile, Dictionary <string, string> globalProperties, ref string warningMsg)
        {
            NPanday.ProjectImporter.Parser.SlnParser.Model.Solution solution;

            List <Dictionary <string, object> > list = new List <Dictionary <string, object> >();

            try
            {
                solution = SolutionFactory.GetSolution(solutionFile);
            }
            catch (Exception exception)
            {
                throw new Exception("Unknown error occurred parsing solution file: " + solutionFile + " (embedded error is: \"" + exception.Message + "\")");
            }

            String UnsupportedProjectsMessage = string.Empty;

            foreach (NPanday.ProjectImporter.Parser.SlnParser.Model.Project project in solution.Projects)
            {
                Dictionary <string, object> dictionary = new Dictionary <string, object>();

                string fullpath = Path.Combine(solutionFile.DirectoryName, project.ProjectPath);

                VisualStudioProjectTypeEnum type;
                try
                {
                    // Skip folders
                    // TODO: merge with method in VS Add-in
                    if (project.ProjectTypeGUID.Equals("{66A26720-8FB5-11D2-AA7E-00C04F688DDE}", StringComparison.OrdinalIgnoreCase) ||
                        project.ProjectTypeGUID.Equals("{2150E333-8FDC-42A3-9474-1A3956D46DE8}", StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }
                    else
                    {
                        type = VisualStudioProjectType.GetVisualStudioProjectType(project.ProjectTypeGUID);
                    }
                }
                catch (Exception e)
                {
                    log.ErrorFormat("Error reading project with type GUID {0}: {1}", project.ProjectTypeGUID, e.Message);
                    if (string.Empty.Equals(UnsupportedProjectsMessage))
                    {
                        UnsupportedProjectsMessage += project.ProjectName;
                    }
                    else
                    {
                        UnsupportedProjectsMessage += ", " + project.ProjectName;
                    }
                    continue;
                }

                dictionary.Add("ProjectType", type);
                dictionary.Add("ProjectTypeGuid", project.ProjectTypeGUID);
                dictionary.Add("ProjectName", project.ProjectName);
                dictionary.Add("ProjectPath", project.ProjectPath);
                dictionary.Add("ProjectGUID", project.ProjectGUID);
                dictionary.Add("ProjectFullPath", fullpath);

                // this is for web projects
                if ((VisualStudioProjectTypeEnum)dictionary["ProjectType"] == VisualStudioProjectTypeEnum.Web_Site)
                {
                    string[] assemblies = GetWebConfigAssemblies(Path.Combine(fullpath, "web.config"));
                    dictionary.Add("WebConfigAssemblies", assemblies);

                    //get project target framework if available
                    if (project.ProjectSections.Count > 0)
                    {
                        if (project.ProjectSections[0].Map.ContainsKey("TargetFramework"))
                        {
                            dictionary.Add("TargetFramework", project.ProjectSections[0].Map["TargetFramework"]);
                        }
                    }

                    //@001 SERNACIO START retrieving webreference
                    Digest.Model.WebReferenceUrl[] webReferences = getWebReferenceUrls(fullpath);
                    dictionary.Add("WebReferencesUrl", webReferences);
                    //@001 SERNACIO END retrieving webreference

                    string[] binAssemblies = GetBinAssemblies(Path.Combine(fullpath, @"bin"));
                    dictionary.Add("BinAssemblies", binAssemblies);
                    //ParseInnerData(dictionary, match.Groups["projectInnerData"].ToString());
                    ParseProjectReferences(dictionary, project, solution);
                }
                // this is for normal projects
                else
                {
                    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, and ignore the visualstudioversion
                        if (globalProperties != null)
                        {
                            foreach (KeyValuePair <string, string> entry in globalProperties)
                            {
                                prj.GlobalProperties.SetProperty(entry.Key, entry.Value);
                            }
                        }

                        // Some debugging to troubleshoot an infrequent error where Microsoft.Build throws a NullReferenceException.
                        // This may have been mitigated by setting VisualStudioVersion and can be removed if the problem doesn't re-appear.
                        if (log.IsDebugEnabled)
                        {
                            log.DebugFormat("VisualStudioVersion: global {0}, evaluated {1}",
                                            prj.GlobalProperties["VisualStudioVersion"], prj.EvaluatedProperties["VisualStudioVersion"]);
                            log.DebugFormat("CloudExtensionsDir: global {0}, evaluated {1}",
                                            prj.GlobalProperties["CloudExtensionsDir"], prj.EvaluatedProperties["CloudExtensionsDir"]);
                            log.DebugFormat("MSBuildExtensionsPath: global {0}, evaluated {1}",
                                            prj.GlobalProperties["MSBuildExtensionsPath"], prj.EvaluatedProperties["MSBuildExtensionsPath"]);
                        }

                        prj.Load(fullpath);
                    }
                    catch (NullReferenceException e)
                    {
                        log.Error("Error reading project from path " + fullpath, e);
                        // workaround it by removing the imports
                        prj.LoadXml(TransformProjectFile(fullpath));
                        prj.FullFileName = fullpath;
                    }
                    catch (Exception e)
                    {
                        log.Error("Error reading project from path " + fullpath, e);
                        if (string.Empty.Equals(UnsupportedProjectsMessage))
                        {
                            UnsupportedProjectsMessage += project.ProjectName;
                        }
                        else
                        {
                            UnsupportedProjectsMessage += ", " + project.ProjectName;
                        }
                        continue;
                    }

                    //ParseInnerData(dictionary, match.Groups["projectInnerData"].ToString());
                    ParseProjectReferences(dictionary, project, solution);
                    dictionary.Add("Project", prj);
                }

                list.Add(dictionary);
            }
            if (!string.Empty.Equals(UnsupportedProjectsMessage))
            {
                warningMsg = string.Format("{0}\n    Unsupported Projects: {1}", warningMsg, UnsupportedProjectsMessage);
            }

            return(list);
        }
示例#2
0
        public List <Dictionary <string, object> > Parse(FileInfo solutionFile, ref string warningMsg)
        {
            NPanday.ProjectImporter.Parser.SlnParser.Model.Solution solution;

            List <Dictionary <string, object> > list = new List <Dictionary <string, object> >();

            try
            {
                solution = SolutionFactory.GetSolution(solutionFile);
            }
            catch (Exception exception)
            {
                throw new Exception("Unknown error occurred parsing solution file: " + solutionFile + " (embedded error is: \"" + exception.Message + "\")");
            }

            String UnsupportedProjectsMessage = string.Empty;

            foreach (NPanday.ProjectImporter.Parser.SlnParser.Model.Project project in solution.Projects)
            {
                Dictionary <string, object> dictionary = new Dictionary <string, object>();

                string fullpath = Path.Combine(solutionFile.DirectoryName, project.ProjectPath);

                VisualStudioProjectTypeEnum type;
                try
                {
                    type = VisualStudioProjectType.GetVisualStudioProjectType(project.ProjectTypeGUID);
                }
                catch (Exception)
                {
                    if (string.Empty.Equals(UnsupportedProjectsMessage))
                    {
                        UnsupportedProjectsMessage += project.ProjectName;
                    }
                    else
                    {
                        UnsupportedProjectsMessage += ", " + project.ProjectName;
                    }
                    continue;
                }

                dictionary.Add("ProjectType", type);
                dictionary.Add("ProjectTypeGuid", project.ProjectTypeGUID);
                dictionary.Add("ProjectName", project.ProjectName);
                dictionary.Add("ProjectPath", project.ProjectPath);
                dictionary.Add("ProjectGUID", project.ProjectGUID);
                dictionary.Add("ProjectFullPath", fullpath);

                // this is for web projects
                if ((VisualStudioProjectTypeEnum)dictionary["ProjectType"] == VisualStudioProjectTypeEnum.Web_Site)
                {
                    string[] assemblies = GetWebConfigAssemblies(Path.Combine(fullpath, "web.config"));
                    dictionary.Add("WebConfigAssemblies", assemblies);

                    //get project target framework if available
                    if (project.ProjectSections.Count > 0)
                    {
                        if (project.ProjectSections[0].Map.ContainsKey("TargetFramework"))
                        {
                            dictionary.Add("TargetFramework", project.ProjectSections[0].Map["TargetFramework"]);
                        }
                    }

                    //@001 SERNACIO START retrieving webreference
                    Digest.Model.WebReferenceUrl[] webReferences = getWebReferenceUrls(fullpath);
                    dictionary.Add("WebReferencesUrl", webReferences);
                    //@001 SERNACIO END retrieving webreference

                    string[] binAssemblies = GetBinAssemblies(Path.Combine(fullpath, @"bin"));
                    dictionary.Add("BinAssemblies", binAssemblies);
                    //ParseInnerData(dictionary, match.Groups["projectInnerData"].ToString());
                    ParseProjectReferences(dictionary, project, solution);
                }
                // this is for normal projects
                else
                {
                    Microsoft.Build.BuildEngine.Project prj = new Microsoft.Build.BuildEngine.Project(BUILD_ENGINE);

                    prj.Load(fullpath);

                    //ParseInnerData(dictionary, match.Groups["projectInnerData"].ToString());
                    ParseProjectReferences(dictionary, project, solution);
                    dictionary.Add("Project", prj);
                }

                list.Add(dictionary);
            }
            if (!string.Empty.Equals(UnsupportedProjectsMessage))
            {
                warningMsg = string.Format("{0}\n    Unsupported Projects: {1}", warningMsg, UnsupportedProjectsMessage);
            }

            return(list);
        }