diff --git a/src/Features/Core/Portable/CodeRefactorings/AddMissingImports/AbstractAddMissingImportsFeatureService.cs b/src/Features/Core/Portable/CodeRefactorings/AddMissingImports/AbstractAddMissingImportsFeatureService.cs index 3df3b2ca2808c..9d265b448d029 100644 --- a/src/Features/Core/Portable/CodeRefactorings/AddMissingImports/AbstractAddMissingImportsFeatureService.cs +++ b/src/Features/Core/Portable/CodeRefactorings/AddMissingImports/AbstractAddMissingImportsFeatureService.cs @@ -48,7 +48,10 @@ public async Task AddMissingImportsAsync(Document document, TextSpan te } // Find fixes for the diagnostic where there is only a single fix. - var usableFixes = await GetUnambiguousFixesAsync(document, diagnostics, cancellationToken).ConfigureAwait(false); + var unambiguousFixes = await GetUnambiguousFixesAsync(document, diagnostics, cancellationToken).ConfigureAwait(false); + + // We do not want to add project or framework references without the user's input, so filter those out. + var usableFixes = unambiguousFixes.WhereAsArray(fixData => DoesNotAddReference(fixData, document.Project.Id)); if (usableFixes.IsEmpty) { return document.Project; @@ -59,6 +62,13 @@ public async Task AddMissingImportsAsync(Document document, TextSpan te return newDocument.Project; } + private bool DoesNotAddReference(AddImportFixData fixData, ProjectId currentProjectId) + { + return (fixData.ProjectReferenceToAdd is null || fixData.ProjectReferenceToAdd == currentProjectId) + && (fixData.PortableExecutableReferenceProjectId is null || fixData.PortableExecutableReferenceProjectId == currentProjectId) + && string.IsNullOrEmpty(fixData.AssemblyReferenceAssemblyName); + } + private async Task> GetDiagnosticsAsync(Document document, TextSpan textSpan, CancellationToken cancellationToken) { var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);