/// <summary> /// find project /// </summary> /// <param name="solutionFilePath"></param> /// <param name="project"></param> /// <param name="ownerProject"></param> /// <returns></returns> private bool ProjectFinder(string solutionFilePath, ProjectDescription project, out IList <ProjectDescription> ownerProjects) { var projectList = _solutionParser.Parser(solutionFilePath); ownerProjects = new List <ProjectDescription>(); if (projectList != null && projectList.Any()) { foreach (var proj in projectList) { var referProjects = MsToolkit.GetReferAssembly(proj.ProjectFile); if (referProjects.Where(p => p.ToLower().Contains(project.ProjectGuid.ToLower())).ToList().Count() != 0) { var ProjectParserFactory = ContainerManager.Resolve <IProjectParserServiceFactory>(); var projectParser = ProjectParserFactory.Create(AnalysisFileType.CSPROJ); var projectx = projectParser.Parser(proj.ProjectFile); if (!_projectFilter.IsValid(Path.GetFileName(proj.ProjectFile))) { continue; } if (projectx.ProjectType == VsProjectType.ClassLibrary || projectx.ProjectType == VsProjectType.Undefined) { continue; } projectx.Name = proj.Name; projectx.Location = new FileInfo(proj.ProjectFile).Directory; projectx.FullName = proj.ProjectFile; projectx.IsNeedCompile = false; ownerProjects.Add(projectx); } } return(ownerProjects.Count > 0); } return(false); }
public bool Do(string filePath) { if (!projectFiler.IsValidFile(filePath)) { return(false); } var logger = ContainerManager.Resolve <ILogger>(); logger.AppendLog(PackPeriod.Analysis, Path.GetFileName(filePath)); if (PackContext.ProjectsDescription.Where(p => p.StaticFiles.Any(x => x.Equals(filePath))).ToList().Count > 0) { var description = PackContext.ProjectsDescription.Where(p => p.ContentFiles.Any(x => filePath.EndsWith(x))).First(); logger.DebugTrace(filePath + "已存在项目中"); if (!filePath.EndsWith(".cshtml")) { description.StaticFiles.Add(filePath); } else { description.HtmlFiles.Add(filePath); } return(true); } FileInfo file = new FileInfo(filePath); if (file.Exists) { var directory = file.Directory; int csprojCount = 0; do { try { var projlist = directory.EnumerateFiles().ToList() .Where(p => p.Extension.EndsWith(Constants.PROJECTEXTENSION)).ToList(); csprojCount = projlist.Count; foreach (var item in projlist) { //get collection of content files from project file var contentFiles = MsToolkit.GetProjectContentFiles(item.FullName) .Select(p => $"{directory.FullName}\\{p}"); if (contentFiles.FirstOrDefault(p => p == filePath) != null) { //find project which owned it from the context ProjectDescription projDescription = null; if ((projDescription = PackContext.ProjectsDescription .FirstOrDefault(p => p.Name == item.Name && p.Location.FullName == item.Directory.FullName)) != null) { //add file to the collection of statics files if (!filePath.EndsWith(".cshtml")) { projDescription.StaticFiles.Add(filePath); } else { projDescription.HtmlFiles.Add(filePath); } return(true); } else { //解析项目文件 var ProjectParserFactory = ContainerManager.Resolve <IProjectParserServiceFactory>(); var projectParser = ProjectParserFactory.Create(AnalysisFileType.CSPROJ); var description = projectParser.Parser(item.FullName); description.Name = item.Name; description.Location = item.Directory; description.IsChanged = false; description.FullName = item.FullName; description.IsNeedCompile = false; //add file to the collection of statics files if (!filePath.EndsWith(".cshtml")) { description.StaticFiles.Add(filePath); } else { description.HtmlFiles.Add(filePath); } PackContext.ProjectsDescription.Add(description); return(true); } } } } catch (Exception ex) { logger.Error(filePath + "=>" + ex.Message); return(false); } directory = directory.Parent; }while (csprojCount == 0 && directory != null); } return(false); }
public void TestGetProjectIncludeFiles() { var list = MsToolkit.GetProjectCompileFiles(@"D:\WorkSpace\New\GHB2C\Website\Presentation\GH.Web\GH.Web.csproj"); Console.WriteLine("ss"); }