public static RoslynWorkspace GetWorkspace(AvalonStudio.Projects.ISolution solution, bool create = true) { lock (s_solutionWorkspaces) { if (!s_solutionWorkspaces.ContainsKey(solution)) { if (!create) { return(null); } //await PackageManager.EnsurePackage("AvalonStudio.Languages.CSharp", IoC.Get<IConsole>()); //var dotnetDirectory = Path.Combine(PackageManager.GetPackageDirectory("AvalonStudio.Languages.CSharp"), "content"); var currentDir = AvalonStudio.Platforms.Platform.ExecutionPath; var loadedAssemblies = System.AppDomain.CurrentDomain.GetAssemblies(); var assemblies = new[] { // Microsoft.CodeAnalysis.Workspaces typeof(WorkspacesResources).GetTypeInfo().Assembly, // Microsoft.CodeAnalysis.CSharp.Workspaces typeof(CSharpWorkspaceResources).GetTypeInfo().Assembly, // Microsoft.CodeAnalysis.Features typeof(FeaturesResources).GetTypeInfo().Assembly, // Microsoft.CodeAnalysis.CSharp.Features typeof(CSharpFeaturesResources).GetTypeInfo().Assembly, typeof(RoslynWorkspace).Assembly, }; var partTypes = MefHostServices.DefaultAssemblies.Concat(assemblies) .Distinct() .SelectMany(x => x.GetTypes()) .ToArray(); var compositionContext = new ContainerConfiguration() .WithParts(partTypes) .CreateContainer(); var host = MefHostServices.Create(compositionContext); var workspace = new RoslynWorkspace(host, null, compositionContext, DotNetCliService.Instance.Info.Executable, DotNetCliService.Instance.Info.BasePath); workspace.RegisterWorkspace(solution); workspace.InitialiseBuildNodesAsync(true).Wait(); } return(s_solutionWorkspaces[solution]); } }
public static void DisposeWorkspace(AvalonStudio.Projects.ISolution solution) { lock (s_solutionWorkspaces) { if (s_solutionWorkspaces.ContainsKey(solution)) { var workspace = s_solutionWorkspaces[solution]; s_solutionWorkspaces.Remove(solution); workspace.Dispose(); workspace.DisposeNodes(); } } }
internal RoslynWorkspace RegisterWorkspace(AvalonStudio.Projects.ISolution solution) => s_solutionWorkspaces[solution] = this;