Ejemplo n.º 1
0
        private static bool IsWebApplication(this SlnProjectInfo p)
        {
            string projectPath = Path.GetDirectoryName(p.FullPath);

            // 如果在项目文件目录下发现web.config就认为是WEB项目
            string flagFile = Path.Combine(projectPath, "web.config");

            return(File.Exists(flagFile));
        }
Ejemplo n.º 2
0
        public static List <SlnProjectInfo> GetProjects(string slnFilePath)
        {
            if (File.Exists(slnFilePath) == false)
            {
                throw new FileNotFoundException("文件不存在:" + slnFilePath);
            }

            if (slnFilePath.EndsWith(".sln", StringComparison.OrdinalIgnoreCase) == false)
            {
                throw new ArgumentException("参数不是解决方案文件名。");
            }

            List <SlnProjectInfo> list = new List <SlnProjectInfo>();

            string slnDirectory = Path.GetDirectoryName(slnFilePath);

            string[] lines = File.ReadAllLines(slnFilePath, Encoding.UTF8);

            foreach (string line in lines)
            {
                Match m = s_project.Match(line);
                if (m.Success)
                {
                    string typeGuid = m.Groups["type"].Value;
                    if (typeGuid == "2150E333-8FDC-42A3-9474-1A3956D46DE8")                             // Solution Folder
                    {
                        continue;
                    }

                    // http://www.cnblogs.com/landywzx/archive/2013/02/05/2893332.html
                    if (typeGuid == "E24C65DC-7377-472B-9ABA-BC803B73C61A")                             // website
                    {
                        continue;
                    }

                    SlnProjectInfo project = new SlnProjectInfo();
                    project.Name = m.Groups["name"].Value;
                    project.File = m.Groups["file"].Value;
                    project.Guid = m.Groups["guid"].Value;

                    // 计算项目文件的全路径
                    project.FullPath = Path.Combine(slnDirectory, project.File);


                    // 项目的程序集名称和编译模式都是在第一个节点中指定的。
                    Project csproj = ParseCsprojFile(project.FullPath);
                    project.AssemblyName = csproj.Groups[0].AssemblyName;
                    project.CompilerMode = csproj.Groups[0].Configuration;

                    string outputPath = GetProjectOutputPath(csproj);
                    if (string.IsNullOrEmpty(outputPath))
                    {
                        throw new FormatException("不能解析项目文件的编译输出目录:" + project.FullPath);
                    }
                    project.OutputPath = Path.Combine(Path.GetDirectoryName(project.FullPath), outputPath);

                    list.Add(project);
                }
            }
            return(list);
        }