当前位置: 首页>>代码示例>>C#>>正文


C# AdhocWorkspace.AddProject方法代码示例

本文整理汇总了C#中AdhocWorkspace.AddProject方法的典型用法代码示例。如果您正苦于以下问题:C# AdhocWorkspace.AddProject方法的具体用法?C# AdhocWorkspace.AddProject怎么用?C# AdhocWorkspace.AddProject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AdhocWorkspace的用法示例。


在下文中一共展示了AdhocWorkspace.AddProject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CheckPEReferencesSameAfterSolutionChangedTest

        public async Task CheckPEReferencesSameAfterSolutionChangedTest()
        {
            using (var ws = new AdhocWorkspace())
            {
                var projectInfo = ProjectInfo.Create(
                    ProjectId.CreateNewId(),
                    VersionStamp.Create(),
                    "TestProject",
                    "TestProject",
                    LanguageNames.CSharp,
                    metadataReferences: ImmutableArray.Create<MetadataReference>(PortableExecutableReference.CreateFromFile(typeof(object).Assembly.Location)));

                var project = ws.AddProject(projectInfo);

                // get original references
                var compilation1 = await project.GetCompilationAsync();
                var references1 = compilation1.ExternalReferences;

                // just some arbitary action to create new snpahost that doesnt affect references
                var info = DocumentInfo.Create(DocumentId.CreateNewId(project.Id), "code.cs");
                var document = ws.AddDocument(info);

                // get new compilation
                var compilation2 = await document.Project.GetCompilationAsync();
                var references2 = compilation2.ExternalReferences;

                Assert.Equal(references1, references2);
            }
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:29,代码来源:WorkspaceReferenceTests.cs

示例2: TestAddProject_NameAndLanguage

 public void TestAddProject_NameAndLanguage()
 {
     using (var ws = new AdhocWorkspace())
     {
         var project = ws.AddProject("TestProject", LanguageNames.CSharp);
         Assert.Same(project, ws.CurrentSolution.Projects.FirstOrDefault());
         Assert.Equal("TestProject", project.Name);
         Assert.Equal(LanguageNames.CSharp, project.Language);
     }
 }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:10,代码来源:AdhocWorkspaceTests.cs

示例3: CreateSolutionSnapshotId_Project_Serialization

        public async Task CreateSolutionSnapshotId_Project_Serialization()
        {
            var solution = new AdhocWorkspace().CurrentSolution;
            var project = solution.AddProject("Project", "Project.dll", LanguageNames.CSharp);

            var snapshotService = (new SolutionChecksumServiceFactory()).CreateService(solution.Workspace.Services) as ISolutionChecksumService;
            using (var snapshot = await snapshotService.CreateChecksumAsync(project.Solution, CancellationToken.None).ConfigureAwait(false))
            {
                await VerifySnapshotSerializationAsync(snapshotService, solution, snapshot.SolutionChecksum).ConfigureAwait(false);
            }
        }
开发者ID:natidea,项目名称:roslyn,代码行数:11,代码来源:SnapshotSerializationTests.cs

示例4: AcquireCompletionService

        public void AcquireCompletionService()
        {
            var workspace = new AdhocWorkspace();

            var document = workspace
                .AddProject("TestProject", LanguageNames.CSharp)
                .AddDocument("TestDocument.cs", "");

            var service = CompletionService.GetService(document);
            Assert.NotNull(service);
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:11,代码来源:CompletionServiceTests.cs

示例5: TestAddDocument_DocumentInfo

        public void TestAddDocument_DocumentInfo()
        {
            using (var ws = new AdhocWorkspace())
            {
                var project = ws.AddProject("TestProject", LanguageNames.CSharp);
                var info = DocumentInfo.Create(DocumentId.CreateNewId(project.Id), "code.cs");
                var doc = ws.AddDocument(info);

                Assert.Equal(ws.CurrentSolution.GetDocument(info.Id), doc);
                Assert.Equal(info.Name, doc.Name);
            }
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:12,代码来源:AdhocWorkspaceTests.cs

示例6: TestAddDocument_NameAndText

        public void TestAddDocument_NameAndText()
        {
            using (var ws = new AdhocWorkspace())
            {
                var project = ws.AddProject("TestProject", LanguageNames.CSharp);
                var name = "code.cs";
                var source = "class C {}";
                var doc = ws.AddDocument(project.Id, name, SourceText.From(source));

                Assert.Equal(name, doc.Name);
                Assert.Equal(source, doc.GetTextAsync().Result.ToString());
            }
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:13,代码来源:AdhocWorkspaceTests.cs

示例7: GetSolution

        private Solution GetSolution(params string[] sources)
        {
            var ws = new AdhocWorkspace();
            var pid = ProjectId.CreateNewId();

            var docs = sources.Select((s, i) =>
                DocumentInfo.Create(
                    DocumentId.CreateNewId(pid),
                    name: "code" + i,
                    loader: TextLoader.From(TextAndVersion.Create(SourceText.From(s), VersionStamp.Default)))).ToList();

            var proj = ProjectInfo.Create(pid, VersionStamp.Default, "test", "test.dll", LanguageNames.CSharp, documents: docs,
                metadataReferences: new[] { TestReferences.NetFx.v4_0_30319.mscorlib });

            return ws.AddProject(proj).Solution;
        }
开发者ID:ralfkang,项目名称:roslyn,代码行数:16,代码来源:SymbolEditorTests.cs

示例8: CreateSolutionSnapshotId_Project

        public async Task CreateSolutionSnapshotId_Project()
        {
            var solution = new AdhocWorkspace().CurrentSolution;
            var project = solution.AddProject("Project", "Project.dll", LanguageNames.CSharp);

            var snapshotService = (new SolutionChecksumServiceFactory()).CreateService(solution.Workspace.Services) as ISolutionChecksumService;
            using (var snapshot = await snapshotService.CreateChecksumAsync(project.Solution, CancellationToken.None).ConfigureAwait(false))
            {
                var solutionId = snapshot.SolutionChecksum;
                VerifyChecksumObjectInService(snapshotService, solutionId);
                VerifyChecksumInService(snapshotService, solutionId.Info, WellKnownChecksumObjects.SolutionChecksumObjectInfo);
                VerifyChecksumObjectInService(snapshotService, solutionId.Projects);

                Assert.Equal(solutionId.Projects.Count, 1);
                VerifySnapshotInService(snapshotService, solutionId.Projects.ToProjectObjects(snapshotService)[0], 0, 0, 0, 0, 0);
            }
        }
开发者ID:natidea,项目名称:roslyn,代码行数:17,代码来源:SnapshotSerializationTests.cs

示例9: TestAddProject_ProjectInfo

        public void TestAddProject_ProjectInfo()
        {
            var info = ProjectInfo.Create(
                ProjectId.CreateNewId(),
                version: VersionStamp.Default,
                name: "TestProject",
                assemblyName: "TestProject.dll",
                language: LanguageNames.CSharp);

            using (var ws = new AdhocWorkspace())
            {
                var project = ws.AddProject(info);
                Assert.Equal(project, ws.CurrentSolution.Projects.FirstOrDefault());
                Assert.Equal(info.Name, project.Name);
                Assert.Equal(info.Id, project.Id);
                Assert.Equal(info.AssemblyName, project.AssemblyName);
                Assert.Equal(info.Language, project.Language);
            }
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:19,代码来源:AdhocWorkspaceTests.cs

示例10: AcquireCompletionService

        public void AcquireCompletionService()
        {
            var hostServices = MefHostServices.Create(
                MefHostServices.DefaultAssemblies.Concat(
                    new[]
                    {
                        typeof(CompletionService).Assembly,
                        typeof(CSharpCompletionService).Assembly
                    }));

            var workspace = new AdhocWorkspace(hostServices);

            var document = workspace
                .AddProject("TestProject", LanguageNames.CSharp)
                .AddDocument("TestDocument.cs", "");

            var service = CompletionService.GetService(document);
            Assert.NotNull(service);
        }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:19,代码来源:CompletionServiceTests.cs

示例11: CheckPEReferencesNotSameAfterReferenceChangedTest

        public async Task CheckPEReferencesNotSameAfterReferenceChangedTest()
        {
            using (var ws = new AdhocWorkspace())
            {
                var projectInfo = ProjectInfo.Create(
                    ProjectId.CreateNewId(),
                    VersionStamp.Create(),
                    "TestProject",
                    "TestProject",
                    LanguageNames.CSharp,
                    metadataReferences: ImmutableArray.Create<MetadataReference>(PortableExecutableReference.CreateFromFile(typeof(object).Assembly.Location)));

                var project = ws.AddProject(projectInfo);

                // get original references
                var compilation1 = await project.GetCompilationAsync();
                var references1 = compilation1.ExternalReferences;

                // explicitly change references
                var forkedProject = project.WithMetadataReferences(ImmutableArray.Create<MetadataReference>(
                    PortableExecutableReference.CreateFromFile(typeof(object).Assembly.Location),
                    PortableExecutableReference.CreateFromFile(typeof(Workspace).Assembly.Location)));

                // get new compilation
                var compilation2 = await forkedProject.GetCompilationAsync();
                var references2 = compilation2.ExternalReferences;

                Assert.NotEqual(references1, references2);
            }
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:30,代码来源:WorkspaceReferenceTests.cs

示例12: TestOpenCloseAdditionalDocument

        public void TestOpenCloseAdditionalDocument()
        {
            var pid = ProjectId.CreateNewId();
            var text = SourceText.From("public class C { }");
            var version = VersionStamp.Create();
            var docInfo = DocumentInfo.Create(DocumentId.CreateNewId(pid), "c.cs", loader: TextLoader.From(TextAndVersion.Create(text, version)));
            var projInfo = ProjectInfo.Create(
                pid,
                version: VersionStamp.Default,
                name: "TestProject",
                assemblyName: "TestProject.dll",
                language: LanguageNames.CSharp,
                additionalDocuments: new[] { docInfo });

            using (var ws = new AdhocWorkspace())
            {
                ws.AddProject(projInfo);

                SourceText currentText;
                VersionStamp currentVersion;

                var doc = ws.CurrentSolution.GetAdditionalDocument(docInfo.Id);
                Assert.Equal(false, doc.TryGetText(out currentText));

                ws.OpenAdditionalDocument(docInfo.Id);

                doc = ws.CurrentSolution.GetAdditionalDocument(docInfo.Id);
                Assert.Equal(true, doc.TryGetText(out currentText));
                Assert.Equal(true, doc.TryGetTextVersion(out currentVersion));
                Assert.Same(text, currentText);
                Assert.Equal(version, currentVersion);

                ws.CloseAdditionalDocument(docInfo.Id);

                doc = ws.CurrentSolution.GetAdditionalDocument(docInfo.Id);
                Assert.Equal(false, doc.TryGetText(out currentText));
            }
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:38,代码来源:AdhocWorkspaceTests.cs

示例13: TestRemoveProject_TryApplyChanges

        public void TestRemoveProject_TryApplyChanges()
        {
            var pid = ProjectId.CreateNewId();
            var info = ProjectInfo.Create(
                pid,
                version: VersionStamp.Default,
                name: "TestProject",
                assemblyName: "TestProject.dll",
                language: LanguageNames.CSharp);

            using (var ws = new AdhocWorkspace())
            {
                ws.AddProject(info);

                Assert.Equal(1, ws.CurrentSolution.Projects.Count());

                var newSolution = ws.CurrentSolution.RemoveProject(pid);
                Assert.Equal(0, newSolution.Projects.Count());

                var result = ws.TryApplyChanges(newSolution);
                Assert.Equal(true, result);

                Assert.Equal(0, ws.CurrentSolution.Projects.Count());
            }
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:25,代码来源:AdhocWorkspaceTests.cs

示例14: GetDocument

 private Document GetDocument(string code)
 {
     var ws = new AdhocWorkspace();
     var project = ws.AddProject("project", LanguageNames.CSharp);
     return project.AddDocument("code", SourceText.From(code));
 }
开发者ID:GloryChou,项目名称:roslyn,代码行数:6,代码来源:FormattingTreeEditTests.cs

示例15: SnapshotWithMissingReferencesTest

        public async Task SnapshotWithMissingReferencesTest()
        {
            var hostServices = MefHostServices.Create(
                MefHostServices.DefaultAssemblies.Add(typeof(Host.TemporaryStorageServiceFactory.TemporaryStorageService).Assembly));

            var solution = new AdhocWorkspace(hostServices).CurrentSolution;
            var project1 = solution.AddProject("Project", "Project.dll", LanguageNames.CSharp);

            var metadata = new MissingMetadataReference();
            var analyzer = new AnalyzerFileReference("missing_reference", new MissingAnalyzerLoader());

            project1 = project1.AddMetadataReference(metadata);
            project1 = project1.AddAnalyzerReference(analyzer);

            var snapshotService = (new SolutionChecksumServiceFactory()).CreateService(solution.Workspace.Services) as ISolutionChecksumService;
            using (var snapshot = await snapshotService.CreateChecksumAsync(project1.Solution, CancellationToken.None).ConfigureAwait(false))
            {
                // this shouldn't throw
                var recovered = await GetSolutionAsync(snapshotService, snapshot).ConfigureAwait(false);
            }
        }
开发者ID:orthoxerox,项目名称:roslyn,代码行数:21,代码来源:SnapshotSerializationTests.cs


注:本文中的AdhocWorkspace.AddProject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。