Skip to content

Commit 9a179e3

Browse files
authored
Merge pull request #3961 from mavasani/MultipleFiles
Ensure that we do not add duplicate public API files for multi-tfm pr…
2 parents 17181ac + 0f87aa4 commit 9a179e3

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/PublicApiAnalyzers/Core/CodeFixes/DeclarePublicApiFix.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,10 +295,15 @@ await publicSurfaceAreaAdditionalDocument.GetTextAsync(cancellationToken).Config
295295
newSolution = newSolution.WithAdditionalDocumentText(pair.Key, pair.Value);
296296
}
297297

298+
// NOTE: We need to avoid creating duplicate files for multi-tfm projects. See https://github.com/dotnet/roslyn-analyzers/issues/3952.
299+
using var uniqueProjectPaths = PooledHashSet<string>.GetInstance();
298300
foreach (KeyValuePair<ProjectId, SourceText> pair in addedPublicSurfaceAreaText)
299301
{
300302
var project = newSolution.GetProject(pair.Key);
301-
newSolution = AddPublicApiFiles(project, pair.Value);
303+
if (uniqueProjectPaths.Add(project.FilePath ?? project.Name))
304+
{
305+
newSolution = AddPublicApiFiles(project, pair.Value);
306+
}
302307
}
303308

304309
return newSolution;

0 commit comments

Comments
 (0)