/// <inheritdoc /> protected override IEnumerable <Project> GetProjects(IExecutionContext context, IFile file) { StringWriter log = new StringWriter(); AnalyzerManager manager = new AnalyzerManager(new AnalyzerManagerOptions { LogWriter = log }); ProjectAnalyzer analyzer = manager.GetProject(file.Path.FullPath); if (context.Bool(CodeAnalysisKeys.OutputBuildLog)) { analyzer.WithBinaryLog(); } CompileProjectAndTrace(analyzer, log); AdhocWorkspace workspace = analyzer.GetWorkspace(); return(workspace.CurrentSolution.Projects); }
private Compilation AddProjectReferences(IExecutionContext context, List <ISymbol> symbols, Compilation compilation) { // Generate a single Workspace and add all of the projects to it StringWriter log = new StringWriter(); AnalyzerManager manager = new AnalyzerManager(new AnalyzerManagerOptions { LogWriter = log }); AdhocWorkspace workspace = new AdhocWorkspace(); IEnumerable <IFile> projectFiles = context.FileSystem.GetInputFiles(_projectGlobs) .Where(x => x.Path.Extension == ".csproj" && x.Exists); List <Project> projects = new List <Project>(); foreach (IFile projectFile in projectFiles) { Project project = workspace.CurrentSolution.Projects.FirstOrDefault(x => new FilePath(x.FilePath).Equals(projectFile.Path)); if (project != null) { Trace.Verbose($"Project {projectFile.Path.FullPath} was already in the workspace"); } else { Trace.Verbose($"Creating workspace project for {projectFile.Path.FullPath}"); ProjectAnalyzer analyzer = manager.GetProject(projectFile.Path.FullPath); if (context.Bool(CodeAnalysisKeys.OutputBuildLog)) { analyzer.WithBinaryLog(); } ReadWorkspace.CompileProjectAndTrace(analyzer, log); project = analyzer.AddToWorkspace(workspace); if (!project.Documents.Any()) { Trace.Warning($"Project at {projectFile.Path.FullPath} contains no documents, which may be an error (check previous log output for any MSBuild warnings)"); } } projects.Add(project); } compilation = AddProjectReferences(projects, symbols, compilation); return(compilation); }