コード例 #1
0
        public async Task <ImmutableArray <ReferenceInfo> > GetUnusedReferencesAsync(Solution solution, string projectFilePath, string projectAssetsFilePath, ImmutableArray <ReferenceInfo> projectReferences, CancellationToken cancellationToken)
        {
            using var logger = Logger.LogBlock(FunctionId.UnusedReferences_GetUnusedReferences, message: null, cancellationToken, LogLevel.Information);
            var client = await RemoteHostClient.TryGetClientAsync(solution.Workspace, cancellationToken).ConfigureAwait(false);

            if (client != null)
            {
                var result = await client.TryInvokeAsync <IRemoteUnusedReferenceAnalysisService, ImmutableArray <ReferenceInfo> >(
                    solution,
                    (service, solutionInfo, cancellationToken) => service.GetUnusedReferencesAsync(solutionInfo, projectFilePath, projectAssetsFilePath, projectReferences, cancellationToken),
                    cancellationToken).ConfigureAwait(false);

                if (!result.HasValue)
                {
                    return(ImmutableArray <ReferenceInfo> .Empty);
                }

                return(result.Value);
            }

            // Read specified references with dependency information from the project assets file.
            var references = await ProjectAssetsFileReader.ReadReferencesAsync(projectReferences, projectAssetsFilePath).ConfigureAwait(false);

            // Determine unused references
            var unusedReferences = await UnusedReferencesRemover.GetUnusedReferencesAsync(solution, projectFilePath, references, cancellationToken).ConfigureAwait(false);

            // Remove dependency information before returning.
            return(unusedReferences.SelectAsArray(reference => reference.WithDependencies(null)));
        }
コード例 #2
0
        public async Task <ImmutableArray <ReferenceInfo> > GetUnusedReferencesAsync(Solution solution, string projectFilePath, string projectAssetsFilePath, ImmutableArray <ReferenceInfo> projectReferences, CancellationToken cancellationToken)
        {
            using var logger = Logger.LogBlock(FunctionId.UnusedReferences_GetUnusedReferences, message: null, cancellationToken, LogLevel.Information);
            var client = await RemoteHostClient.TryGetClientAsync(solution.Workspace, cancellationToken).ConfigureAwait(false);

            if (client != null)
            {
                var result = await client.TryInvokeAsync <IRemoteUnusedReferenceAnalysisService, ImmutableArray <ReferenceInfo> >(
                    solution,
                    (service, solutionInfo, cancellationToken) => service.GetUnusedReferencesAsync(solutionInfo, projectFilePath, projectAssetsFilePath, projectReferences, cancellationToken),
                    cancellationToken).ConfigureAwait(false);

                if (!result.HasValue)
                {
                    return(ImmutableArray <ReferenceInfo> .Empty);
                }

                return(result.Value);
            }

            var references = await ProjectAssetsFileReader.ReadReferencesAsync(projectReferences, projectAssetsFilePath).ConfigureAwait(false);

            return(await UnusedReferencesRemover.GetUnusedReferencesAsync(solution, projectFilePath, references, cancellationToken).ConfigureAwait(false));
        }