Visual Studio 2012 introduced a very helpful feature called Code Clone Analysis, which will search the solution and find out the duplicate code snippets.
If you worked in any maintenance or support project, one of
the main challenges is to find out the duplicate code, which makes the system
less maintainable. Visual Studio introduced the new Code Clone Analysis
feature, which will tell us whether a code snippet exists in any of the files
in the solution or not.
Code Clone Analysis
For our sample, I am using the default ASP.Net web
application with dummy code copied across the solution.
Select the code snippet and right click.
Select “Find Matching Clones in Solution” option from the
You can find the Code Clone Analysis result displayed. From
the result window, you can navigate directly to specified code files.
From the results window, you can compare two matching code
snippets using the Comparison tool
The output of the Comparison tool
Solution Level Code Clone Analysis
Instead of searching for a particular code snippet, we can
perform the Code Clone Analysis on solution level also.
Select the Analyze Solution for Code Clone option from the
This will search the entire solution and display all the
cloned code details. In our sample, we have 4 matches found. As you can observe
from the Code Clone analysis Results window, the analysis results will be displayed
depends on the degree of match found and how many files are involved in a
particular code clone match.
We have 4 matches with 4 Clone groups – Exact Match, Strong
Match, Medium Match and Weak Match.
Expanded view of the Code Clone Analysis results
Visual Studio 2012 introduced many new features to boost the
developer productivity. One of the main features is the Code Clone Analysis,
which analyze the code and output the duplicate or cloned code snippets