Reputation: 699
When I do code merge between branches sometimes the auto merge in Visual Studio 2022 may result in duplicated code segments or duplicated methods. So in such a scenario, I need to efficiently find and remove the duplicated code segments.
How can I find duplicated lines or duplicated code segments in Visual Studio 2022? Is there a method for it or are there any plugins available to download?
I am aware the for Visual Studio Code there's a plug-in by the name duplicate-lines-finder (https://marketplace.visualstudio.com/items?itemName=tlevesque2.duplicate-finder) but what I need is for Visual Studio 2022
Upvotes: 7
Views: 7359
Reputation: 13842
You can identify C# Code Duplicate with NDepend (free trial here).
The open-source command line power tool lists suspect code this way:
And then typing "o" will open the source code:
More details about how it works here: Find C# Code Duplicate
Upvotes: 0
Reputation: 6975
If you use Visual Studio Community Edition, you can install CodeRush extension, from DevExpress (https://www.devexpress.com/products/coderush)
It's free (https://www.devexpress.com/coderush-free) and quite powerful.
See the documentation for Duplicate Code analysis: https://docs.devexpress.com/CodeRushForRoslyn/401720/static-code-analysis/duplicate-code
Upvotes: 4
Reputation: 3688
In Visual Studio Enterprise, first install
Visual Studio Installer=>Individual Components => Code Tools => Code Clone
Then use Visual Studio Enterprise Edition to open your project and click
Analyze=> Analyze Solution For Code Clones to find duplicate code blocks
Upvotes: 6