Example #1
0
        public void LoadProject(string path)
        {
            //ProjectPath = path;
            string fullPath = "";

            if (Solution != null)
            {
                fullPath = Solution.SolutionPath.Replace(Solution.Name, "");
            }
            if (ProjectPath.EndsWith(".csproj") || ProjectPath.EndsWith(".vbproj"))
            {
                #region Reading Project
                fullPath = fullPath + ProjectPath;
                System.Xml.XmlDocument document = new System.Xml.XmlDocument();
                document.Load(fullPath);
                System.Xml.XmlNodeList itemGroupNodeList = document.GetElementsByTagName("ItemGroup");
                foreach (System.Xml.XmlNode node in itemGroupNodeList)
                {
                    foreach (System.Xml.XmlNode nodeChild in node.ChildNodes)
                    {
                        try
                        {
                            if (nodeChild.Name.ToLower() == "reference")
                            {
                                ProjectReference reference = new ProjectReference();
                                reference.Include = nodeChild.Attributes["Include"].Value;
                                if (this.ProjectReferences == null)
                                {
                                    this.ProjectReferences = new List <ProjectReference>();
                                }
                                this.ProjectReferences.Add(reference);
                            }
                            else if (nodeChild.Name.ToLower() == "compile")
                            {
                                string []     fullFilePaths = nodeChild.Attributes["Include"].Value.Split('\\');
                                int           count         = 1;
                                ProjectFolder folder        = null;
                                foreach (string str in fullFilePaths)
                                {
                                    if (fullFilePaths.Length == count)
                                    {
                                        ProjectFiles file = new ProjectFiles();
                                        file.Include = nodeChild.Attributes["Include"].Value;
                                        int index = file.Include.LastIndexOf('\\');
                                        index++;
                                        if (index < 0)
                                        {
                                            index = 0;
                                        }

                                        file.Name = file.Include.Substring(index, file.Include.Length - index);
                                        if (folder == null)
                                        {
                                            this.ProjectFiles.Add(file);
                                        }
                                        else
                                        {
                                            folder.Files.Add(file);
                                        }
                                    }
                                    else
                                    {
                                        bool          Exists       = false;
                                        ProjectFolder parentFolder = folder;
                                        if (parentFolder == null)
                                        {
                                            folder = ProjectFolder.GetFolder(str, this.ProjectFolders, out Exists);
                                        }
                                        else
                                        {
                                            folder = ProjectFolder.GetFolder(str, parentFolder.Folders, out Exists);
                                        }
                                        if (!Exists)
                                        {
                                            folder.Parent = parentFolder;
                                            if (parentFolder == null)
                                            {
                                                this.ProjectFolders.Add(folder);
                                            }
                                            else
                                            {
                                                parentFolder.Folders.Add(folder);
                                            }
                                        }
                                    }
                                    count++;
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            continue;
                        }
                    }
                }
                #endregion
            }
            else
            {
                fullPath = fullPath + ProjectPath;
                DirectoryInfo dirInfo = new DirectoryInfo(fullPath);
                if (dirInfo != null)
                {
                    GetFolderProjectStructure(dirInfo, null);
                }
            }
        }