private ProjectContextCollection AddProjectContextEntry(string projectDirectory, ProjectContextCollection currentEntry) { if (currentEntry == null) { // new entry required currentEntry = new ProjectContextCollection(); } var projectEntry = GetProject(projectDirectory); if (projectEntry.Model == null) { // project doesn't exist anymore currentEntry.Reset(); return(currentEntry); } var project = projectEntry.Model; if (currentEntry.HasChanged) { currentEntry.Reset(); foreach (var framework in project.GetTargetFrameworks()) { var builder = new ProjectContextBuilder() .WithProjectResolver(path => GetProject(path).Model) .WithLockFileResolver(path => GetLockFile(path)) .WithProject(project) .WithTargetFramework(framework.FrameworkName) .AsDesignTime(); currentEntry.ProjectContexts.Add(builder.Build()); } currentEntry.Project = project; currentEntry.ProjectFilePath = project.ProjectFilePath; currentEntry.LastProjectFileWriteTimeUtc = File.GetLastWriteTimeUtc(currentEntry.ProjectFilePath); var lockFilePath = Path.Combine(project.ProjectDirectory, LockFile.FileName); if (File.Exists(lockFilePath)) { currentEntry.LockFilePath = lockFilePath; currentEntry.LastLockFileWriteTimeUtc = File.GetLastWriteTimeUtc(lockFilePath); } currentEntry.ProjectDiagnostics.AddRange(projectEntry.Diagnostics); } return(currentEntry); }
private ProjectContextCollection AddProjectContextEntry(string projectDirectory, ProjectContextCollection currentEntry) { if (currentEntry == null) { // new entry required currentEntry = new ProjectContextCollection(); } var projectEntry = GetProjectCore(projectDirectory); if (projectEntry?.Model == null) { // project doesn't exist anymore currentEntry.Reset(); return(currentEntry); } var project = projectEntry.Model; if (currentEntry.HasChanged) { currentEntry.Reset(); var contexts = BuildProjectContexts(project); currentEntry.ProjectContexts.AddRange(contexts); currentEntry.Project = project; currentEntry.ProjectFilePath = project.ProjectFilePath; currentEntry.LastProjectFileWriteTimeUtc = File.GetLastWriteTimeUtc(currentEntry.ProjectFilePath); var lockFilePath = Path.Combine(project.ProjectDirectory, LockFile.FileName); if (File.Exists(lockFilePath)) { currentEntry.LockFilePath = lockFilePath; currentEntry.LastLockFileWriteTimeUtc = File.GetLastWriteTimeUtc(lockFilePath); } currentEntry.ProjectDiagnostics.AddRange(projectEntry.Diagnostics); currentEntry.ProjectDiagnostics.AddRange( currentEntry.ProjectContexts.SelectMany(c => c.Diagnostics)); } return(currentEntry); }