示例#1
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);
        }
示例#2
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);
        }