sm101
sm101

Reputation: 699

How to identify duplicate code in Visual Studio 2022

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

Answers (3)

Patrick from NDepend team
Patrick from NDepend team

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: C# Code Duplicate found

And then typing "o" will open the source code:

C# Code Duplicate More details about how it works here: Find C# Code Duplicate

Upvotes: 0

Silvio Delgado
Silvio Delgado

Reputation: 6975

CodeRush

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

Wenbin Geng
Wenbin Geng

Reputation: 3688

In Visual Studio Enterprise, first install

Visual Studio Installer=>Individual Components => Code Tools => Code Clone

enter image description here

Then use Visual Studio Enterprise Edition to open your project and click

Analyze=> Analyze Solution For Code Clones to find duplicate code blocks

enter image description here

enter image description here

Upvotes: 6

Related Questions