コード例 #1
0
        internal static Solution CreateFullSolution(HostServices?hostServices = null)
        {
            var solution        = new AdhocWorkspace(hostServices ?? Host.Mef.MefHostServices.DefaultHost).CurrentSolution;
            var languages       = ImmutableHashSet.Create(LanguageNames.CSharp, LanguageNames.VisualBasic);
            var solutionOptions = solution.Workspace.Services.GetRequiredService <IOptionService>().GetSerializableOptionsSnapshot(languages);

            solution = solution.WithOptions(solutionOptions);

            var csCode    = "class A { }";
            var project1  = solution.AddProject("Project", "Project.dll", LanguageNames.CSharp);
            var document1 = project1.AddDocument("Document1", SourceText.From(csCode));

            var vbCode    = "Class B\r\nEnd Class";
            var project2  = document1.Project.Solution.AddProject("Project2", "Project2.dll", LanguageNames.VisualBasic);
            var document2 = project2.AddDocument("Document2", SourceText.From(vbCode));

            solution = document2.Project.Solution.GetRequiredProject(project1.Id)
                       .AddProjectReference(new ProjectReference(project2.Id, ImmutableArray.Create("test")))
                       .AddMetadataReference(MetadataReference.CreateFromFile(typeof(object).Assembly.Location))
                       .AddAnalyzerReference(new AnalyzerFileReference(Path.Combine(TempRoot.Root, "path1"), new TestAnalyzerAssemblyLoader()))
                       .AddAdditionalDocument("Additional", SourceText.From("hello"), ImmutableArray.Create("test"), @".\Add").Project.Solution;

            return(solution
                   .WithAnalyzerReferences(new[] { new AnalyzerFileReference(Path.Combine(TempRoot.Root, "path2"), new TestAnalyzerAssemblyLoader()) })
                   .AddAnalyzerConfigDocuments(
                       ImmutableArray.Create(
                           DocumentInfo.Create(
                               DocumentId.CreateNewId(project1.Id),
                               ".editorconfig",
                               loader: TextLoader.From(TextAndVersion.Create(SourceText.From("root = true"), VersionStamp.Create()))))));
        }