コード例 #1
0
        /// <summary>
        /// 加载项目文件
        /// </summary>
        /// <param name="fileName">文件名</param>
        public override void LoadProjectFile(string fileName)
        {
            string ext = FileHelper.GetExtension(fileName);

            if (ext == "VBPROJ")
            {
                string txt = FileHelper.LoadAnsiFile(fileName);
                System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
                doc.LoadXml(txt);
                foreach (System.Xml.XmlElement element in doc.SelectNodes("VisualStudioProject/VisualBasic/Files/Include/File"))
                {
                    ProjectFileEntity NewFile = new ProjectFileEntity();
                    NewFile.FileName   = element.GetAttribute("RelPath");
                    NewFile.CanAnalyse = (element.GetAttribute("BuildAction") == "Compile");
                    this.files.Add(NewFile);
                }
                this.projectFileName = fileName;
                this.rootPath        = System.IO.Path.GetDirectoryName(fileName);
            }
            else if (ext == "VBP")
            {
                using (System.IO.StreamReader reader = new System.IO.StreamReader(
                           fileName,
                           System.Text.Encoding.GetEncoding(936)))
                {
                    string strLine = reader.ReadLine();
                    while (strLine != null)
                    {
                        int    index    = strLine.IndexOf("=");
                        string strName  = strLine.Substring(0, index);
                        string strValue = strLine.Substring(index + 1);

                        if (strName == "Form" ||
                            strName == "Module" ||
                            strName == "Class" ||
                            strName == "UserControl")
                        {
                            index = strValue.IndexOf(";");
                            if (index > 0)
                            {
                                strValue = strValue.Substring(index + 1);
                            }
                            strValue = strValue.Trim();
                            if (strValue.Length > 0)
                            {
                                ProjectFileEntity NewFile = new ProjectFileEntity();
                                NewFile.FileName   = strValue;
                                NewFile.CanAnalyse = true;
                                this.files.Add(NewFile);
                            }
                        }
                        strLine = reader.ReadLine();
                    }
                    this.projectFileName = fileName;
                    this.rootPath        = System.IO.Path.GetDirectoryName(fileName);
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// 载入C#工程项目文件
        /// </summary>
        /// <param name="fileName">文件名</param>
        public override void LoadProjectFile(string fileName)
        {
            this.projectFileName = fileName;

            System.IO.StreamReader myReader = new System.IO.StreamReader(fileName, System.Text.Encoding.GetEncoding(936));
            string strText = myReader.ReadToEnd();

            myReader.Close();

            System.Xml.XmlDocument myXMLDoc = new System.Xml.XmlDocument();
            myXMLDoc.LoadXml(strText);

            this.rootPath = System.IO.Path.GetDirectoryName(fileName);
            this.files.Clear();

            bool For2005 = false;

            if (myXMLDoc.DocumentElement.Name == "Project")
            {
                if (myXMLDoc.DocumentElement.GetAttribute("xmlns") == "http://schemas.microsoft.com/developer/msbuild/2003")
                {
                    For2005 = true;
                }
            }

            if (For2005)
            {
                System.Xml.XmlNamespaceManager ns = new System.Xml.XmlNamespaceManager(myXMLDoc.NameTable);
                ns.AddNamespace("a", "http://schemas.microsoft.com/developer/msbuild/2003");
                foreach (System.Xml.XmlElement myFileElement in myXMLDoc.SelectNodes("a:Project/a:ItemGroup/a:Compile", ns))
                {
                    ProjectFileEntity NewFile = new ProjectFileEntity();
                    NewFile.FileName = myFileElement.GetAttribute("Include");
                    string name = NewFile.FileName;
                    name = name.Trim().ToLower();
                    if (name.EndsWith(".cs"))
                    {
                        NewFile.CanAnalyse = true;
                    }
                    else
                    {
                        NewFile.CanAnalyse = false;
                    }
                    this.files.Add(NewFile);
                }
            }
            else
            {
                foreach (System.Xml.XmlElement myFileElement in myXMLDoc.SelectNodes("VisualStudioProject/CSHARP/Files/Include/File"))
                {
                    ProjectFileEntity NewFile = new ProjectFileEntity();
                    NewFile.FileName   = myFileElement.GetAttribute("RelPath");
                    NewFile.CanAnalyse = (myFileElement.GetAttribute("BuildAction") == "Compile");
                    this.files.Add(NewFile);
                }
            }
        }