本文整理汇总了C#中AdhocWorkspace.AddSolution方法的典型用法代码示例。如果您正苦于以下问题:C# AdhocWorkspace.AddSolution方法的具体用法?C# AdhocWorkspace.AddSolution怎么用?C# AdhocWorkspace.AddSolution使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AdhocWorkspace
的用法示例。
在下文中一共展示了AdhocWorkspace.AddSolution方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateSolution
private static Solution CreateSolution(int solutionSize)
{
var info = SolutionInfo.Create(SolutionId.CreateNewId(), VersionStamp.Create());
var workspace = new AdhocWorkspace();
workspace.AddSolution(info);
var solution = workspace.CurrentSolution;
var project = solution.AddProject("proj1", "proj1", LanguageNames.CSharp);
var current = 0;
for (var i = 0; true; i++)
{
var size = current + 1234;
if (current + size >= solutionSize)
{
break;
}
project = project.AddDocument("doc" + i, new string('a', size)).Project;
current += size;
}
var left = solutionSize - current;
if (left > 0)
{
project = project.AddDocument("docLast", new string('a', left)).Project;
}
return project.Solution;
}
示例2: TestAddSolution_SolutionInfo
public void TestAddSolution_SolutionInfo()
{
using (var ws = new AdhocWorkspace())
{
var pinfo = ProjectInfo.Create(
ProjectId.CreateNewId(),
version: VersionStamp.Default,
name: "TestProject",
assemblyName: "TestProject.dll",
language: LanguageNames.CSharp);
var sinfo = SolutionInfo.Create(SolutionId.CreateNewId(), VersionStamp.Default, projects: new ProjectInfo[] { pinfo });
var solution = ws.AddSolution(sinfo);
Assert.Same(ws.CurrentSolution, solution);
Assert.Equal(solution.Id, sinfo.Id);
Assert.Equal(sinfo.Projects.Count, solution.ProjectIds.Count);
var project = solution.Projects.FirstOrDefault();
Assert.NotNull(project);
Assert.Equal(pinfo.Name, project.Name);
Assert.Equal(pinfo.Id, project.Id);
Assert.Equal(pinfo.AssemblyName, project.AssemblyName);
Assert.Equal(pinfo.Language, project.Language);
}
}
示例3: GetSolutionAsync
private async Task<Solution> GetSolutionAsync(ISolutionChecksumService service, ChecksumScope snapshot)
{
var workspace = new AdhocWorkspace();
var solutionInfo = await GetValueAsync<SolutionChecksumObjectInfo>(service, snapshot.SolutionChecksum.Info, WellKnownChecksumObjects.SolutionChecksumObjectInfo).ConfigureAwait(false);
var projects = new List<ProjectInfo>();
foreach (var projectSnapshot in snapshot.SolutionChecksum.Projects.ToProjectObjects(service))
{
var documents = new List<DocumentInfo>();
foreach (var documentSnapshot in projectSnapshot.Documents.ToDocumentObjects(service))
{
var documentInfo = await GetValueAsync<DocumentChecksumObjectInfo>(service, documentSnapshot.Info, WellKnownChecksumObjects.DocumentChecksumObjectInfo).ConfigureAwait(false);
var text = await GetValueAsync<SourceText>(service, documentSnapshot.Text, WellKnownChecksumObjects.SourceText).ConfigureAwait(false);
// TODO: do we need version?
documents.Add(
DocumentInfo.Create(
documentInfo.Id,
documentInfo.Name,
documentInfo.Folders,
documentInfo.SourceCodeKind,
TextLoader.From(TextAndVersion.Create(text, VersionStamp.Create())),
documentInfo.FilePath,
documentInfo.IsGenerated));
}
var p2p = new List<ProjectReference>();
foreach (var checksum in projectSnapshot.ProjectReferences)
{
var reference = await GetValueAsync<ProjectReference>(service, checksum, WellKnownChecksumObjects.ProjectReference).ConfigureAwait(false);
p2p.Add(reference);
}
var metadata = new List<MetadataReference>();
foreach (var checksum in projectSnapshot.MetadataReferences)
{
var reference = await GetValueAsync<MetadataReference>(service, checksum, WellKnownChecksumObjects.MetadataReference).ConfigureAwait(false);
metadata.Add(reference);
}
var analyzers = new List<AnalyzerReference>();
foreach (var checksum in projectSnapshot.AnalyzerReferences)
{
var reference = await GetValueAsync<AnalyzerReference>(service, checksum, WellKnownChecksumObjects.AnalyzerReference).ConfigureAwait(false);
analyzers.Add(reference);
}
var additionals = new List<DocumentInfo>();
foreach (var documentSnapshot in projectSnapshot.AdditionalDocuments.ToDocumentObjects(service))
{
var documentInfo = await GetValueAsync<DocumentChecksumObjectInfo>(service, documentSnapshot.Info, WellKnownChecksumObjects.DocumentChecksumObjectInfo).ConfigureAwait(false);
var text = await GetValueAsync<SourceText>(service, documentSnapshot.Text, WellKnownChecksumObjects.SourceText).ConfigureAwait(false);
// TODO: do we need version?
additionals.Add(
DocumentInfo.Create(
documentInfo.Id,
documentInfo.Name,
documentInfo.Folders,
documentInfo.SourceCodeKind,
TextLoader.From(TextAndVersion.Create(text, VersionStamp.Create())),
documentInfo.FilePath,
documentInfo.IsGenerated));
}
var projectInfo = await GetValueAsync<ProjectChecksumObjectInfo>(service, projectSnapshot.Info, WellKnownChecksumObjects.ProjectChecksumObjectInfo).ConfigureAwait(false);
var compilationOptions = await GetValueAsync<CompilationOptions>(service, projectSnapshot.CompilationOptions, WellKnownChecksumObjects.CompilationOptions).ConfigureAwait(false);
var parseOptions = await GetValueAsync<ParseOptions>(service, projectSnapshot.ParseOptions, WellKnownChecksumObjects.ParseOptions).ConfigureAwait(false);
projects.Add(
ProjectInfo.Create(
projectInfo.Id, projectInfo.Version, projectInfo.Name, projectInfo.AssemblyName,
projectInfo.Language, projectInfo.FilePath, projectInfo.OutputFilePath,
compilationOptions, parseOptions,
documents, p2p, metadata, analyzers, additionals));
}
return workspace.AddSolution(SolutionInfo.Create(solutionInfo.Id, solutionInfo.Version, solutionInfo.FilePath, projects));
}
示例4: GetSolutionAsync
private async Task<Solution> GetSolutionAsync(ISolutionSynchronizationService service, PinnedRemotableDataScope syncScope)
{
var workspace = new AdhocWorkspace();
var solutionObject = await service.GetValueAsync<SolutionStateChecksums>(syncScope.SolutionChecksum);
var solutionInfo = await service.GetValueAsync<SolutionInfo.SolutionAttributes>(solutionObject.Info).ConfigureAwait(false);
var projects = new List<ProjectInfo>();
foreach (var projectObject in solutionObject.Projects.ToProjectObjects(service))
{
var projectInfo = await service.GetValueAsync<ProjectInfo.ProjectAttributes>(projectObject.Info).ConfigureAwait(false);
if (!workspace.Services.IsSupported(projectInfo.Language))
{
continue;
}
var documents = new List<DocumentInfo>();
foreach (var documentObject in projectObject.Documents.ToDocumentObjects(service))
{
var documentInfo = await service.GetValueAsync<DocumentInfo.DocumentAttributes>(documentObject.Info).ConfigureAwait(false);
var text = await service.GetValueAsync<SourceText>(documentObject.Text).ConfigureAwait(false);
// TODO: do we need version?
documents.Add(
DocumentInfo.Create(
documentInfo.Id,
documentInfo.Name,
documentInfo.Folders,
documentInfo.SourceCodeKind,
TextLoader.From(TextAndVersion.Create(text, VersionStamp.Create())),
documentInfo.FilePath,
documentInfo.IsGenerated));
}
var p2p = new List<ProjectReference>();
foreach (var checksum in projectObject.ProjectReferences)
{
var reference = await service.GetValueAsync<ProjectReference>(checksum).ConfigureAwait(false);
p2p.Add(reference);
}
var metadata = new List<MetadataReference>();
foreach (var checksum in projectObject.MetadataReferences)
{
var reference = await service.GetValueAsync<MetadataReference>(checksum).ConfigureAwait(false);
metadata.Add(reference);
}
var analyzers = new List<AnalyzerReference>();
foreach (var checksum in projectObject.AnalyzerReferences)
{
var reference = await service.GetValueAsync<AnalyzerReference>(checksum).ConfigureAwait(false);
analyzers.Add(reference);
}
var additionals = new List<DocumentInfo>();
foreach (var documentObject in projectObject.AdditionalDocuments.ToDocumentObjects(service))
{
var documentInfo = await service.GetValueAsync<DocumentInfo.DocumentAttributes>(documentObject.Info).ConfigureAwait(false);
var text = await service.GetValueAsync<SourceText>(documentObject.Text).ConfigureAwait(false);
// TODO: do we need version?
additionals.Add(
DocumentInfo.Create(
documentInfo.Id,
documentInfo.Name,
documentInfo.Folders,
documentInfo.SourceCodeKind,
TextLoader.From(TextAndVersion.Create(text, VersionStamp.Create())),
documentInfo.FilePath,
documentInfo.IsGenerated));
}
var compilationOptions = await service.GetValueAsync<CompilationOptions>(projectObject.CompilationOptions).ConfigureAwait(false);
var parseOptions = await service.GetValueAsync<ParseOptions>(projectObject.ParseOptions).ConfigureAwait(false);
projects.Add(
ProjectInfo.Create(
projectInfo.Id, projectInfo.Version, projectInfo.Name, projectInfo.AssemblyName,
projectInfo.Language, projectInfo.FilePath, projectInfo.OutputFilePath,
compilationOptions, parseOptions,
documents, p2p, metadata, analyzers, additionals, projectInfo.IsSubmission));
}
return workspace.AddSolution(SolutionInfo.Create(solutionInfo.Id, solutionInfo.Version, solutionInfo.FilePath, projects));
}
示例5: CreateSolutionAsync
//.........这里部分代码省略.........
{
// only add project our workspace supports.
// workspace doesn't allow creating project with unknown languages
continue;
}
var documents = new List<DocumentInfo>();
foreach (var documentChecksum in projectSnapshot.Documents)
{
var documentSnapshot = await _assetService.GetAssetAsync<DocumentStateChecksums>(documentChecksum, cancellationToken).ConfigureAwait(false);
var documentInfo = await _assetService.GetAssetAsync<DocumentInfo.DocumentAttributes>(documentSnapshot.Info, cancellationToken).ConfigureAwait(false);
var textLoader = TextLoader.From(
TextAndVersion.Create(
new ChecksumSourceText(
documentSnapshot.Text,
await _assetService.GetAssetAsync<SourceText>(documentSnapshot.Text, cancellationToken).ConfigureAwait(false)),
VersionStamp.Create(),
documentInfo.FilePath));
// TODO: do we need version?
documents.Add(
DocumentInfo.Create(
documentInfo.Id,
documentInfo.Name,
documentInfo.Folders,
documentInfo.SourceCodeKind,
textLoader,
documentInfo.FilePath,
documentInfo.IsGenerated));
}
var p2p = new List<ProjectReference>();
foreach (var checksum in projectSnapshot.ProjectReferences)
{
cancellationToken.ThrowIfCancellationRequested();
var reference = await _assetService.GetAssetAsync<ProjectReference>(checksum, cancellationToken).ConfigureAwait(false);
p2p.Add(reference);
}
var metadata = new List<MetadataReference>();
foreach (var checksum in projectSnapshot.MetadataReferences)
{
cancellationToken.ThrowIfCancellationRequested();
var reference = await _assetService.GetAssetAsync<MetadataReference>(checksum, cancellationToken).ConfigureAwait(false);
metadata.Add(reference);
}
var analyzers = new List<AnalyzerReference>();
foreach (var checksum in projectSnapshot.AnalyzerReferences)
{
cancellationToken.ThrowIfCancellationRequested();
var reference = await _assetService.GetAssetAsync<AnalyzerReference>(checksum, cancellationToken).ConfigureAwait(false);
analyzers.Add(reference);
}
var additionals = new List<DocumentInfo>();
foreach (var documentChecksum in projectSnapshot.AdditionalDocuments)
{
cancellationToken.ThrowIfCancellationRequested();
var documentSnapshot = await _assetService.GetAssetAsync<DocumentStateChecksums>(documentChecksum, cancellationToken).ConfigureAwait(false);
var documentInfo = await _assetService.GetAssetAsync<DocumentInfo.DocumentAttributes>(documentSnapshot.Info, cancellationToken).ConfigureAwait(false);
var textLoader = TextLoader.From(
TextAndVersion.Create(
new ChecksumSourceText(
documentSnapshot.Text,
await _assetService.GetAssetAsync<SourceText>(documentSnapshot.Text, cancellationToken).ConfigureAwait(false)),
VersionStamp.Create(),
documentInfo.FilePath));
// TODO: do we need version?
additionals.Add(
DocumentInfo.Create(
documentInfo.Id,
documentInfo.Name,
documentInfo.Folders,
documentInfo.SourceCodeKind,
textLoader,
documentInfo.FilePath,
documentInfo.IsGenerated));
}
var compilationOptions = await _assetService.GetAssetAsync<CompilationOptions>(projectSnapshot.CompilationOptions, cancellationToken).ConfigureAwait(false);
var parseOptions = await _assetService.GetAssetAsync<ParseOptions>(projectSnapshot.ParseOptions, cancellationToken).ConfigureAwait(false);
projects.Add(
ProjectInfo.Create(
projectInfo.Id, projectInfo.Version, projectInfo.Name, projectInfo.AssemblyName,
projectInfo.Language, projectInfo.FilePath, projectInfo.OutputFilePath,
compilationOptions, parseOptions,
documents, p2p, metadata, analyzers, additionals, projectInfo.IsSubmission));
}
return workspace.AddSolution(SolutionInfo.Create(solutionInfo.Id, solutionInfo.Version, solutionInfo.FilePath, projects));
}
示例6: CreateOrOpenSolution
private Solution CreateOrOpenSolution()
{
string solutionFile = Path.Combine(_persistentFolder, "Solution1.sln");
bool newSolution;
if (newSolution = !File.Exists(solutionFile))
{
File.WriteAllText(solutionFile, "");
}
var info = SolutionInfo.Create(SolutionId.CreateNewId(), VersionStamp.Create(), solutionFile);
var workspace = new AdhocWorkspace();
workspace.AddSolution(info);
var solution = workspace.CurrentSolution;
if (newSolution)
{
string projectFile = Path.Combine(Path.GetDirectoryName(solutionFile), "Project1.csproj");
File.WriteAllText(projectFile, "");
solution = solution.AddProject(ProjectInfo.Create(ProjectId.CreateNewId(), VersionStamp.Create(), "Project1", "Project1", LanguageNames.CSharp, projectFile));
var project = solution.Projects.Single();
string documentFile = Path.Combine(Path.GetDirectoryName(projectFile), "Document1.cs");
File.WriteAllText(documentFile, "");
solution = solution.AddDocument(DocumentInfo.Create(DocumentId.CreateNewId(project.Id), "Document1", filePath: documentFile));
}
return solution;
}
示例7: TestP2PReference
public void TestP2PReference()
{
var workspace = new AdhocWorkspace();
var project1 = ProjectInfo.Create(ProjectId.CreateNewId(), VersionStamp.Default, "proj1", "proj1", LanguageNames.CSharp);
var project2 = ProjectInfo.Create(ProjectId.CreateNewId(), VersionStamp.Default, "proj2", "proj2", LanguageNames.CSharp, projectReferences: SpecializedCollections.SingletonEnumerable(new ProjectReference(project1.Id)));
var solutionInfo = SolutionInfo.Create(SolutionId.CreateNewId(), VersionStamp.Default, projects: new ProjectInfo[] { project1, project2 });
var solution = workspace.AddSolution(solutionInfo);
var instance = new object();
var weak = new WeakReference(instance);
var cacheService = new ProjectCacheService(workspace, int.MaxValue);
using (var cache = cacheService.EnableCaching(project2.Id))
{
cacheService.CacheObjectIfCachingEnabledForKey(project1.Id, (object)null, instance);
instance = null;
solution = null;
workspace.OnProjectRemoved(project1.Id);
workspace.OnProjectRemoved(project2.Id);
}
// make sure p2p reference doesnt go to implicit cache
CollectGarbage();
Assert.False(weak.IsAlive);
}
示例8: CreateSolutionAsync
private async Task<Solution> CreateSolutionAsync(Checksum solutionChecksum, CancellationToken cancellationToken)
{
var solutionChecksumObject = await RoslynServices.AssetService.GetAssetAsync<SolutionChecksumObject>(solutionChecksum, cancellationToken).ConfigureAwait(false);
// TODO: Make these to do work concurrently
var workspace = new AdhocWorkspace(RoslynServices.HostServices);
var solutionInfo = await RoslynServices.AssetService.GetAssetAsync<SolutionChecksumObjectInfo>(solutionChecksumObject.Info, cancellationToken).ConfigureAwait(false);
var projects = new List<ProjectInfo>();
foreach (var projectChecksum in solutionChecksumObject.Projects)
{
var projectSnapshot = await RoslynServices.AssetService.GetAssetAsync<ProjectChecksumObject>(projectChecksum, cancellationToken).ConfigureAwait(false);
var documents = new List<DocumentInfo>();
foreach (var documentChecksum in projectSnapshot.Documents)
{
var documentSnapshot = await RoslynServices.AssetService.GetAssetAsync<DocumentChecksumObject>(documentChecksum, cancellationToken).ConfigureAwait(false);
var documentInfo = await RoslynServices.AssetService.GetAssetAsync<DocumentChecksumObjectInfo>(documentSnapshot.Info, cancellationToken).ConfigureAwait(false);
// TODO: do we need version?
documents.Add(
DocumentInfo.Create(
documentInfo.Id,
documentInfo.Name,
documentInfo.Folders,
documentInfo.SourceCodeKind,
new RemoteTextLoader(documentSnapshot.Text),
documentInfo.FilePath,
documentInfo.IsGenerated));
}
var p2p = new List<ProjectReference>();
foreach (var checksum in projectSnapshot.ProjectReferences)
{
cancellationToken.ThrowIfCancellationRequested();
var reference = await RoslynServices.AssetService.GetAssetAsync<ProjectReference>(checksum, cancellationToken).ConfigureAwait(false);
p2p.Add(reference);
}
var metadata = new List<MetadataReference>();
foreach (var checksum in projectSnapshot.MetadataReferences)
{
cancellationToken.ThrowIfCancellationRequested();
var reference = await RoslynServices.AssetService.GetAssetAsync<MetadataReference>(checksum, cancellationToken).ConfigureAwait(false);
metadata.Add(reference);
}
var analyzers = new List<AnalyzerReference>();
foreach (var checksum in projectSnapshot.AnalyzerReferences)
{
cancellationToken.ThrowIfCancellationRequested();
var reference = await RoslynServices.AssetService.GetAssetAsync<AnalyzerReference>(checksum, cancellationToken).ConfigureAwait(false);
analyzers.Add(reference);
}
var additionals = new List<DocumentInfo>();
foreach (var documentChecksum in projectSnapshot.AdditionalDocuments)
{
cancellationToken.ThrowIfCancellationRequested();
var documentSnapshot = await RoslynServices.AssetService.GetAssetAsync<DocumentChecksumObject>(documentChecksum, cancellationToken).ConfigureAwait(false);
var documentInfo = await RoslynServices.AssetService.GetAssetAsync<DocumentChecksumObjectInfo>(documentSnapshot.Info, cancellationToken).ConfigureAwait(false);
// TODO: do we need version?
additionals.Add(
DocumentInfo.Create(
documentInfo.Id,
documentInfo.Name,
documentInfo.Folders,
documentInfo.SourceCodeKind,
new RemoteTextLoader(documentSnapshot.Text),
documentInfo.FilePath,
documentInfo.IsGenerated));
}
var projectInfo = await RoslynServices.AssetService.GetAssetAsync<ProjectChecksumObjectInfo>(projectSnapshot.Info, cancellationToken).ConfigureAwait(false);
var compilationOptions = await RoslynServices.AssetService.GetAssetAsync<CompilationOptions>(projectSnapshot.CompilationOptions, cancellationToken).ConfigureAwait(false);
var parseOptions = await RoslynServices.AssetService.GetAssetAsync<ParseOptions>(projectSnapshot.ParseOptions, cancellationToken).ConfigureAwait(false);
projects.Add(
ProjectInfo.Create(
projectInfo.Id, projectInfo.Version, projectInfo.Name, projectInfo.AssemblyName,
projectInfo.Language, projectInfo.FilePath, projectInfo.OutputFilePath,
compilationOptions, parseOptions,
documents, p2p, metadata, analyzers, additionals));
}
return workspace.AddSolution(SolutionInfo.Create(solutionInfo.Id, solutionInfo.Version, solutionInfo.FilePath, projects));
}