Example #1
0
        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(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);
                    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);
        }
Example #2
0
        /// <inheritdoc />
        protected override IEnumerable <Project> GetProjects(IExecutionContext context, IFile file)
        {
            StringWriter    log     = new StringWriter();
            AnalyzerManager manager = new AnalyzerManager(file.Path.Directory.FullPath, new AnalyzerManagerOptions
            {
                LogWriter = log
            });

            AnalyzerResult[] results = manager.Projects.Values
                                       .Select(analyzer =>
            {
                if (context.Bool(CodeAnalysisKeys.OutputBuildLog))
                {
                    analyzer.AddBinaryLogger();
                }
                return(ReadWorkspace.CompileProjectAndTrace(analyzer, log));
            })
                                       .Where(x => x != null)
                                       .ToArray();

            AdhocWorkspace workspace = new AdhocWorkspace();

            foreach (AnalyzerResult result in results)
            {
                result.AddToWorkspace(workspace);
            }
            return(workspace.CurrentSolution.Projects);
        }
Example #3
0
        private Compilation AddProjectReferences(IExecutionContext context, List <ISymbol> symbols, Compilation compilation)
        {
            // Generate a single Workspace and add all of the projects to it
            MSBuildWorkspace    workspace    = MSBuildWorkspace.Create();
            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}");
                    project = workspace.OpenProjectAsync(projectFile.Path.FullPath).Result;
                    ReadWorkspace.TraceMsBuildWorkspaceDiagnostics(workspace);
                    if (!project.Documents.Any())
                    {
                        Trace.Warning($"Project at {projectFile.Path.FullPath} contains no documents, which may be an error (view verbose output for any MSBuild errors)");
                    }
                }
                projects.Add(project);
            }
            compilation = AddProjectReferences(projects, symbols, compilation);
            return(compilation);
        }
Example #4
0
        private Compilation AddSolutionReferences(IExecutionContext context, List <ISymbol> symbols, Compilation compilation)
        {
            IEnumerable <IFile> solutionFiles = context.FileSystem.GetInputFiles(_solutionGlobs)
                                                .Where(x => x.Path.Extension == ".sln" && x.Exists);

            foreach (IFile solutionFile in solutionFiles)
            {
                Trace.Verbose($"Creating workspace solution for {solutionFile.Path.FullPath}");
                StringWriter    log     = new StringWriter();
                AnalyzerManager manager = new AnalyzerManager(
                    solutionFile.Path.FullPath,
                    new AnalyzerManagerOptions
                {
                    LogWriter = log
                });
                foreach (ProjectAnalyzer analyzer in manager.Projects.Values)
                {
                    if (context.Bool(CodeAnalysisKeys.OutputBuildLog))
                    {
                        analyzer.WithBinaryLog();
                    }
                    ReadWorkspace.CompileProjectAndTrace(analyzer, log);
                }
                Workspace workspace = manager.GetWorkspace();
                compilation = AddProjectReferences(workspace.CurrentSolution.Projects, symbols, compilation);
            }
            return(compilation);
        }
Example #5
0
        private Compilation AddSolutionReferences(IExecutionContext context, List <ISymbol> symbols, Compilation compilation)
        {
            IEnumerable <IFile> solutionFiles = context.FileSystem.GetInputFiles(_solutionGlobs)
                                                .Where(x => x.Path.Extension == ".sln" && x.Exists);

            foreach (IFile solutionFile in solutionFiles)
            {
                Trace.Verbose($"Creating workspace solution for {solutionFile.Path.FullPath}");
                MSBuildWorkspace workspace = MSBuildWorkspace.Create();
                Solution         solution  = workspace.OpenSolutionAsync(solutionFile.Path.FullPath).Result;
                ReadWorkspace.TraceMsBuildWorkspaceDiagnostics(workspace);
                compilation = AddProjectReferences(solution.Projects, symbols, compilation);
            }
            return(compilation);
        }