本文整理汇总了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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例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);
}
}
示例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());
}
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例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);
}
}
示例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));
}
}
示例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());
}
}
示例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));
}
示例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);
}
}