本文整理汇总了C#中Microsoft.CodeAnalysis.AdhocWorkspace.AddSolution方法的典型用法代码示例。如果您正苦于以下问题:C# AdhocWorkspace.AddSolution方法的具体用法?C# AdhocWorkspace.AddSolution怎么用?C# AdhocWorkspace.AddSolution使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.AdhocWorkspace
的用法示例。
在下文中一共展示了AdhocWorkspace.AddSolution方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdaterService
public async Task UpdaterService()
{
var workspace = new AdhocWorkspace(TestHostServices.CreateHostServices());
workspace.Options = workspace.Options.WithChangedOption(RemoteHostOptions.SolutionChecksumMonitorBackOffTimeSpanInMS, 1);
var analyzerReference = new AnalyzerFileReference(typeof(object).Assembly.Location, new NullAssemblyAnalyzerLoader());
var service = CreateRemoteHostClientService(workspace, SpecializedCollections.SingletonEnumerable<AnalyzerReference>(analyzerReference));
service.Enable();
// make sure client is ready
var client = await service.GetRemoteHostClientAsync(CancellationToken.None);
// add solution
workspace.AddSolution(SolutionInfo.Create(SolutionId.CreateNewId(), VersionStamp.Default));
// TODO: use waiter to make sure workspace events and updater is ready.
// this delay is temporary until I set all .Next unit test hardness to setup correctly
await Task.Delay(TimeSpan.FromSeconds(1));
// checksum should already exist
SolutionStateChecksums checksums;
Assert.True(workspace.CurrentSolution.State.TryGetStateChecksums(out checksums));
service.Disable();
}
示例2: UpdaterService
public async Task UpdaterService()
{
var workspace = new AdhocWorkspace(TestHostServices.CreateHostServices());
workspace.Options = workspace.Options.WithChangedOption(RemoteHostOptions.SolutionChecksumMonitorBackOffTimeSpanInMS, 1);
var analyzerReference = new AnalyzerFileReference(typeof(object).Assembly.Location, new NullAssemblyAnalyzerLoader());
var service = CreateRemoteHostClientService(workspace, SpecializedCollections.SingletonEnumerable<AnalyzerReference>(analyzerReference));
service.Enable();
// make sure client is ready
var client = await service.GetRemoteHostClientAsync(CancellationToken.None);
// add solution
workspace.AddSolution(SolutionInfo.Create(SolutionId.CreateNewId(), VersionStamp.Default));
// TODO: use waiter to make sure workspace events and updater is ready.
// this delay is temporary until I set all .Next unit test hardness to setup correctly
await Task.Delay(TimeSpan.FromSeconds(1));
var checksumService = workspace.Services.GetService<ISolutionChecksumService>();
Checksum checksum;
using (var scope = await checksumService.CreateChecksumAsync(workspace.CurrentSolution, CancellationToken.None))
{
// create solution checksum and hold onto the checksum and let it go
checksum = scope.SolutionChecksum.Checksum;
}
// there should be one held in memory by solution checksum updator
var solutionObject = checksumService.GetChecksumObject(checksum, CancellationToken.None);
Assert.Equal(solutionObject.Checksum, checksum);
service.Disable();
}
示例3: SingleFileSolution
private Solution SingleFileSolution(string fileContent)
{
var id = SolutionId.CreateNewId();
var version = new VersionStamp();
var solutionInfo = SolutionInfo.Create(id, version);
var workspace = new AdhocWorkspace();
var solution = workspace.AddSolution(solutionInfo);
var projectId = ProjectId.CreateNewId();
var projectInfo = NewProjectInfo(projectId);
solution = solution.AddProject(projectInfo);
var project = solution.GetProject(projectId);
var root = CSharpSyntaxTree.ParseText(fileContent).GetRoot();
var documentName = DefaultActiveDocument();
var document = project.AddDocument(documentName, root);
return document.Project.Solution;
}
示例4: EmptySolution
private Solution EmptySolution()
{
var id = SolutionId.CreateNewId();
var version = new VersionStamp();
var solutionInfo = SolutionInfo.Create(id, version);
var workspace = new AdhocWorkspace();
var solution = workspace.AddSolution(solutionInfo);
return solution;
}
示例5: CreateProject
/// <summary>
/// Creates a new P# project using the specified references.
/// </summary>
/// <param name="references">MetadataReferences</param>
/// <returns>Project</returns>
private Project CreateProject(ISet<MetadataReference> references)
{
var workspace = new AdhocWorkspace();
var solutionInfo = SolutionInfo.Create(SolutionId.CreateNewId(), VersionStamp.Create());
var solution = workspace.AddSolution(solutionInfo);
var project = workspace.AddProject("Test", "C#");
CompilationOptions options = null;
if (this.Configuration.OptimizationTarget == OptimizationTarget.Debug)
{
options = project.CompilationOptions.WithOptimizationLevel(OptimizationLevel.Debug);
}
else if (this.Configuration.OptimizationTarget == OptimizationTarget.Release)
{
options = project.CompilationOptions.WithOptimizationLevel(OptimizationLevel.Release);
}
project = project.WithCompilationOptions(options);
project = project.AddMetadataReferences(references);
workspace.TryApplyChanges(project.Solution);
return project;
}
示例6: UpdaterService
public async Task UpdaterService()
{
var exportProvider = TestHostServices.CreateMinimalExportProvider();
var workspace = new AdhocWorkspace(TestHostServices.CreateHostServices(exportProvider));
workspace.Options = workspace.Options.WithChangedOption(RemoteHostOptions.SolutionChecksumMonitorBackOffTimeSpanInMS, 1);
var listener = new Listener();
var analyzerReference = new AnalyzerFileReference(typeof(object).Assembly.Location, new NullAssemblyAnalyzerLoader());
var service = CreateRemoteHostClientService(workspace, SpecializedCollections.SingletonEnumerable<AnalyzerReference>(analyzerReference), listener);
service.Enable();
// make sure client is ready
var client = await service.GetRemoteHostClientAsync(CancellationToken.None);
// add solution
workspace.AddSolution(SolutionInfo.Create(SolutionId.CreateNewId(), VersionStamp.Default));
var listeners = exportProvider.GetExports<IAsynchronousOperationListener, FeatureMetadata>();
var workspaceListener = listeners.First(l => l.Metadata.FeatureName == FeatureAttribute.Workspace).Value as IAsynchronousOperationWaiter;
// wait for listener
await workspaceListener.CreateWaitTask();
await listener.CreateWaitTask();
// checksum should already exist
SolutionStateChecksums checksums;
Assert.True(workspace.CurrentSolution.State.TryGetStateChecksums(out checksums));
service.Disable();
}