コード例 #1
0
        private static Solution CreateProjects(string[] sources, string language = LanguageNames.CSharp)
        {
            string fileNamePrefix = DefaultFilePathPrefix;
            string fileExt        = language == LanguageNames.CSharp ? CSharpDefaultFileExt : VisualBasicDefaultExt;


            var solution = new AdhocWorkspace().CurrentSolution;
            int count    = 0;
            List <ProjectReference> projects = new List <ProjectReference>();

            foreach (var source in sources)
            {
                var projectName = TestProjectName + count;
                var projectId   = ProjectId.CreateNewId(debugName: projectName);
                solution = solution.AddProject(projectId, projectName, projectName, language)
                           .AddMetadataReference(projectId, CorlibReference)
                           .AddMetadataReference(projectId, SystemCoreReference)
                           .AddMetadataReference(projectId, CSharpSymbolsReference)
                           .AddMetadataReference(projectId, CodeAnalysisReference)
                           .AddMetadataReference(projectId, Messaging_PrimitivesReference)
                           .AddMetadataReference(projectId, RuntimeLibraryReference)
                           .AddMetadataReference(projectId, DebugReference)
                           .AddMetadataReference(projectId, Messaging_PatternsReference);
                if (count > 0 && count == sources.Length - 1)
                {
                    solution = solution.AddProjectReferences(projectId, projects);
                }
                else
                {
                    projects.Add(new ProjectReference(projectId));
                }

                var newFileName = fileNamePrefix + count + "." + fileExt;
                var documentId  = DocumentId.CreateNewId(projectId, debugName: newFileName);
                solution = solution.AddDocument(documentId, newFileName, SourceText.From(source));
                count++;
            }
            return(solution);
        }