Esempio n. 1
0
            /// <summary>
            /// Gets a metadata reference to the metadata-only-image corresponding to the compilation.
            /// </summary>
            private async Task <MetadataReference> GetMetadataOnlyImageReferenceAsync(
                Solution solution, ProjectReference projectReference, CancellationToken cancellationToken)
            {
                try
                {
                    using (Logger.LogBlock(FunctionId.Workspace_SkeletonAssembly_GetMetadataOnlyImage, cancellationToken))
                    {
                        var projectId = this.ProjectState.Id;
                        var version   = await this.GetDependentSemanticVersionAsync(solution, cancellationToken).ConfigureAwait(false);

                        // get or build compilation up to declaration state. this compilation will be used to provide live xml doc comment
                        var declarationCompilation = await this.GetOrBuildDeclarationCompilationAsync(solution, cancellationToken : cancellationToken).ConfigureAwait(false);

                        MetadataReference reference;
                        if (!MetadataOnlyReference.TryGetReference(solution, projectReference, declarationCompilation, version, out reference))
                        {
                            // using async build lock so we don't get multiple consumers attempting to build metadata-only images for the same compilation.
                            using (await _buildLock.DisposableWaitAsync(cancellationToken).ConfigureAwait(false))
                            {
                                // okay, we still don't have one. bring the compilation to final state since we are going to use it to create skeleton assembly
                                var compilationInfo = await this.GetOrBuildCompilationInfoAsync(solution, lockGate : false, cancellationToken : cancellationToken).ConfigureAwait(false);

                                reference = MetadataOnlyReference.GetOrBuildReference(solution, projectReference, compilationInfo.Compilation, version, cancellationToken);
                            }
                        }

                        return(reference);
                    }
                }
                catch (Exception e) when(FatalError.ReportUnlessCanceled(e))
                {
                    throw ExceptionUtilities.Unreachable;
                }
            }
Esempio n. 2
0
            public async Task <MetadataReference> GetMetadataReferenceAsync(SolutionState solution, ProjectState fromProject, ProjectReference projectReference, CancellationToken cancellationToken)
            {
                var compilation = await GetCompilationAsync(solution, cancellationToken).ConfigureAwait(false);

                // If it's the same language we can just make a CompilationReference
                if (this.ProjectState.LanguageServices == fromProject.LanguageServices)
                {
                    return(compilation.ToMetadataReference(projectReference.Aliases, projectReference.EmbedInteropTypes));
                }
                else
                {
                    var version = await GetDependentSemanticVersionAsync(solution, cancellationToken).ConfigureAwait(false);

                    return(MetadataOnlyReference.GetOrBuildReference(solution, projectReference, compilation, version, cancellationToken));
                }
            }