Skip to content

C#: Deduplicate TargetFrameworks list after replacement#7149

Merged
knutwannheden merged 1 commit intomainfrom
dedup-target-frameworks
Mar 26, 2026
Merged

C#: Deduplicate TargetFrameworks list after replacement#7149
knutwannheden merged 1 commit intomainfrom
dedup-target-frameworks

Conversation

@knutwannheden
Copy link
Copy Markdown
Contributor

Motivation

When a .csproj has multiple TFMs that independently map to the same target through chained upgrade recipes (e.g. UpgradeToDotNet10), ChangeDotNetTargetFramework produces duplicates in the <TargetFrameworks> list. For example, net40;netstandard2.0;net6.0 becomes net40;net10.0;net10.0 instead of net40;net10.0.

Summary

  • Replace StringBuilder-based loop with a LinkedHashSet to collect frameworks after replacement, preserving order while deduplicating
  • Add test case where two TFMs converge to the same target

Test plan

  • New test deduplicatesMultiTfmAfterReplacement verifies net40;netstandard2.0;net6.0net40;net6.0 when replacing netstandard2.0 with net6.0
  • All existing ChangeDotNetTargetFrameworkTest tests pass

When multiple TFMs in a `<TargetFrameworks>` list independently map to
the same new TFM (e.g. via chained upgrade recipes), the result
contained duplicates. Use a LinkedHashSet to preserve order while
eliminating duplicates after replacement.
@github-project-automation github-project-automation bot moved this to In Progress in OpenRewrite Mar 26, 2026
@knutwannheden knutwannheden merged commit e250eba into main Mar 26, 2026
1 check passed
@knutwannheden knutwannheden deleted the dedup-target-frameworks branch March 26, 2026 07:20
@github-project-automation github-project-automation bot moved this from In Progress to Done in OpenRewrite Mar 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant