private static CompilationOptions GetCompilationOptionsWithScriptReferenceResolvers(HostWorkspaceServices services, CompilationOptions compilationOptions, string filePath)
        {
            var metadataService = services.GetRequiredService <IMetadataService>();

            var baseDirectory = PathUtilities.GetDirectoryName(filePath);

            // TODO (https://github.com/dotnet/roslyn/issues/5325, https://github.com/dotnet/roslyn/issues/13886):
            // - Need to have a way to specify these somewhere in VS options.
            // - Add default namespace imports, default metadata references to match csi.rsp
            // - Add default script globals available in 'csi goo.csx' environment: CommandLineScriptGlobals

            var referenceResolver = RuntimeMetadataReferenceResolver.CreateCurrentPlatformResolver(
                searchPaths: ImmutableArray.Create(RuntimeEnvironment.GetRuntimeDirectory()),
                baseDirectory: baseDirectory,
                fileReferenceProvider: (path, properties) => metadataService.GetReference(path, properties));

            return(compilationOptions
                   .WithMetadataReferenceResolver(referenceResolver)
                   .WithSourceReferenceResolver(new SourceFileResolver(searchPaths: ImmutableArray <string> .Empty, baseDirectory)));
        }
        private IList <TestHostProject> CreateSubmissions(
            IEnumerable <XElement> submissionElements,
            ExportProvider exportProvider)
        {
            var submissions     = new List <TestHostProject>();
            var submissionIndex = 0;

            foreach (var submissionElement in submissionElements)
            {
                var submissionName = "Submission" + (submissionIndex++);

                var languageName = GetLanguage(this, submissionElement);

                // The document
                var markupCode = submissionElement.NormalizedValue();
                MarkupTestFile.GetPositionAndSpans(markupCode,
                                                   out var code, out var cursorPosition, out IDictionary <string, ImmutableArray <TextSpan> > spans);

                var languageServices = Services.GetLanguageServices(languageName);

                // The project

                var document  = new TestHostDocument(exportProvider, languageServices, code, submissionName, submissionName, cursorPosition, spans, SourceCodeKind.Script);
                var documents = new List <TestHostDocument> {
                    document
                };

                if (languageName == NoCompilationConstants.LanguageName)
                {
                    submissions.Add(
                        new TestHostProject(
                            languageServices,
                            compilationOptions: null,
                            parseOptions: null,
                            assemblyName: submissionName,
                            projectName: submissionName,
                            references: null,
                            documents: documents,
                            isSubmission: true));
                    continue;
                }

                var metadataService    = Services.GetService <IMetadataService>();
                var metadataResolver   = RuntimeMetadataReferenceResolver.CreateCurrentPlatformResolver(fileReferenceProvider: metadataService.GetReference);
                var syntaxFactory      = languageServices.GetService <ISyntaxTreeFactoryService>();
                var compilationFactory = languageServices.GetService <ICompilationFactoryService>();
                var compilationOptions = compilationFactory.GetDefaultCompilationOptions()
                                         .WithOutputKind(OutputKind.DynamicallyLinkedLibrary)
                                         .WithMetadataReferenceResolver(metadataResolver);

                var parseOptions = syntaxFactory.GetDefaultParseOptions().WithKind(SourceCodeKind.Script);

                var references = CreateCommonReferences(this, submissionElement);

                var project = new TestHostProject(
                    languageServices,
                    compilationOptions,
                    parseOptions,
                    submissionName,
                    submissionName,
                    references,
                    documents,
                    isSubmission: true);

                submissions.Add(project);
            }

            return(submissions);
        }