async Task InitializeCompilationWorkspaceAsync(CancellationToken cancellationToken) { WorkingDirectory = Workbook.WorkingBasePath; if (!WorkingDirectory.DirectoryExists) { WorkingDirectory = Uri.WorkingDirectory; } if (!WorkingDirectory.DirectoryExists) { WorkingDirectory = FilePath.Empty; } if (agent.IsConnected) { await GacCache.InitializingTask; await Agent.Api.AssociateClientSession( ClientSessionAssociationKind.Initial, WorkingDirectory); CompilationWorkspace = await CompilationWorkspaceFactory.CreateWorkspaceAsync(this); } await RefreshForAgentIntegration(); if (CompilationWorkspace == null) { throw new Exception("Unable to get compilation workspace for agent."); } var dependencyResolver = CompilationWorkspace.DependencyResolver; if (WorkingDirectory.DirectoryExists) { dependencyResolver.BaseDirectory = WorkingDirectory; dependencyResolver.AddAssemblySearchPath(WorkingDirectory); } Workbook.WorkingPathChanged += (o, e) => { if (dependencyResolver != null) { dependencyResolver.RemoveAssemblySearchPath(WorkingDirectory); dependencyResolver.RemoveAssemblySearchPath(e.OldBasePath); WorkingDirectory = e.NewBasePath; dependencyResolver.BaseDirectory = WorkingDirectory; dependencyResolver.AddAssemblySearchPath(WorkingDirectory); } }; PostEvent(ClientSessionEventKind.CompilationWorkspaceAvailable); }
async Task LoadPackageIntegrationsAsync( InteractivePackage package, CancellationToken cancellationToken) { // Forms is special-cased because we own it and load the extension from our framework. if (PackageIdComparer.Equals(package.Identity.Id, "Xamarin.Forms")) { await CompilationWorkspaceFactory.LoadFormsAgentExtensions( package.Identity.Version.Version, this, CompilationWorkspace.DependencyResolver, CompilationWorkspace.EvaluationContextId, Agent.IncludePeImage); } var assembliesToLoadOnAgent = new List <ResolvedAssembly> (); // Integration assemblies are not expected to be in a TFM directory—we look for them in // the `xamarin.interactive` folder inside the NuGet package. var packagePath = Workbook .Packages .GetPackageInstallPath(package); var interactivePath = packagePath.Combine("xamarin.interactive"); if (interactivePath.DirectoryExists) { var interactiveAssemblies = interactivePath.EnumerateFiles("*.dll"); foreach (var interactiveReference in interactiveAssemblies) { var resolvedAssembly = CompilationWorkspace .DependencyResolver .ResolveWithoutReferences(interactiveReference); if (HasIntegration(resolvedAssembly)) { assembliesToLoadOnAgent.Add(resolvedAssembly); foreach (var dependency in resolvedAssembly.ExternalDependencies) { if (!(dependency is WebDependency)) { continue; } if (AddNuGetWebResource(dependency.Location, out var id)) { await WorkbookPageViewModel.LoadWorkbookDependencyAsync($"/static/{id}"); } } } } } if (assembliesToLoadOnAgent.Count > 0) { var assembliesToLoad = assembliesToLoadOnAgent.Select(dep => { var peImage = Agent.IncludePeImage ? GetFileBytes(dep.Path) : null; var syms = Agent.IncludePeImage ? GetDebugSymbolsFromAssemblyPath(dep.Path) : null; return(new AssemblyDefinition( dep.AssemblyName, dep.Path, peImage: peImage, debugSymbols: syms )); }).ToArray(); await Agent.Api.LoadAssembliesAsync( CompilationWorkspace.EvaluationContextId, assembliesToLoad); } await RefreshForAgentIntegration(); }