예제 #1
0
        public ProjectInfo CompileProjectInfo(string path)
        {
            ProjectInfo pi = new ProjectInfo(path);
            FileInfo fi = new FileInfo(path);
            bool inDebug = false;
            using (StreamReader sr = new StreamReader(path))
            {
                while (!sr.EndOfStream)
                {
                    string line = sr.ReadLine();
                    string match = null;
                    if (FindMatch(line, "<AssemblyName>", ref match))
                    {
                        string assemblyName = match.Replace("</AssemblyName>", "").Trim();
                        pi.AssemblyName = assemblyName;
                    }
                    else if (FindMatch(line, "<PropertyGroup", ref match))
                    {
                        inDebug = line.Contains("'Debug|AnyCPU'");
                    }
                    else if (FindMatch(line, "<HintPath>", ref match))
                    {
                        string filePath = match.Replace("</HintPath>", "").Trim();
                        if (filePath.StartsWith(".."))
                            filePath = Path.GetFullPath(fi.Directory.FullName + filePath);
                        pi.References.Add(filePath);
                    }
                    else if (inDebug && FindMatch(line, "<OutputPath>", ref match))
                    {
                        string matcher = "..\\";
                        string outputPath = match.Replace("</OutputPath>", "").Trim();
                        if (outputPath.StartsWith("..") && !outputPath.Replace(matcher, "").Contains(matcher))
                            outputPath = matcher + outputPath;
                        if (outputPath.StartsWith(".."))
                            outputPath = Path.GetFullPath(fi.Directory.FullName + outputPath);
                        else if(!outputPath.Contains(":"))
                            outputPath = Path.GetFullPath(fi.Directory.FullName + "\\" + outputPath);
                        pi.OutputPath = outputPath;
                    }
                    else if (!IsCommented(match))
                    {
                        if (FindMatch(line, "<Compile Include=\"", ref match))
                        {
                            if (!IsCommented(match))
                                AddIncludedFile(match, fi, pi);
                        }
                        else if (FindMatch(line, "<Reference Include=\"", ref match))
                        {
                            if (!IsCommented(match))
                            {
                                string includedFile = match;
                                if (includedFile.Contains(","))
                                    includedFile = includedFile.Substring(0, match.IndexOf(","));
                                else
                                {
                                    includedFile = FindAndReplace(match, "\" />");
                                    includedFile = FindAndReplace(includedFile, "\">");
                                }
                                pi.References.Add(includedFile);
                            }
                        }
                        else if (FindMatch(line, "<ProjectReference Include=\"", ref match))
                        {
                            if (!IsCommented(match))
                            {
                                string includedFile = match;
                                includedFile = FindAndReplace(match, "\" />");
                                includedFile = FindAndReplace(includedFile, "\">");
                                var projectFile =
                                    Path.GetFullPath(Path.Combine(path.Substring(0, path.LastIndexOf("\\") + 1),
                                        includedFile));

                                string projAssembly = null;
                                using (StreamReader psr = new StreamReader(projectFile))
                                {
                                    while (!psr.EndOfStream)
                                    {
                                        string projLine = psr.ReadLine();
                                        if (FindMatch(projLine, "<AssemblyName>", ref projAssembly))
                                        {
                                            projAssembly = projAssembly.Replace("</AssemblyName>", "").Trim();
                                            break;
                                        }
                                    }
                                }
                                if (projAssembly != null)
                                    pi.References.Add(projAssembly);
                            }
                        }
                        else if (FindMatch(line, "<None Include=\"", ref match))
                        {
                            if (!IsCommented(match))
                                AddIncludedFile(match, fi, pi);
                        }
                        else if (FindMatch(line, "<EmbeddedResource Include=\"", ref match))
                        {
                            if (!IsCommented(match))
                                AddIncludedFile(match, fi, pi);
                        }
                    }
                }
            }

            return pi;
        }
예제 #2
0
        public bool HasFilesNewerThanAssembly(ProjectInfo projectInfo)
        {
            bool retVal = false;
            string assemblyName = projectInfo.OutputPath + projectInfo.AssemblyName + ".dll";
            var assemblyFileInfo = new FileInfo(assemblyName);

            _logger.WriteLine("");
            _logger.WriteLine("Checking assembly: " + assemblyName);
            if (assemblyFileInfo.Exists)
            {
                DateTime assemblyUpdate = assemblyFileInfo.LastWriteTime;
                foreach (string file in projectInfo.Files)
                {
                    if ((new FileInfo(file)).LastWriteTime > assemblyUpdate)
                    {
                        _logger.WriteLine("File changed: " + file);
                        retVal = true;
                        break;
                    }
                }
                if(!retVal)
                    _logger.WriteLine("No newer files found");
            }
            else
            {
                _logger.WriteLine("Assembly doesn't exist");
            }
            _logger.WriteLine("");
            return retVal;
        }
예제 #3
0
 private void AddIncludedFile(string match, FileInfo fi, ProjectInfo pi)
 {
     string includedFile = FindAndReplace(match, "\" />");
     includedFile = FindAndReplace(includedFile, "\">");
     if (!includedFile.StartsWith(".\\"))
         includedFile = ".\\" + includedFile;
     includedFile = Path.GetFullPath(fi.Directory.FullName + includedFile);
     pi.Files.Add(includedFile);
 }