Visual Studio 2012 Features–Code Clone Analysis

Posted by in Visual Studio category on for Beginner level | Points: 250 | Views : 11352 red flag
Rating: 4 out of 5  
 1 vote(s)

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 Context Menu

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 Analyze Menu.

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 information.


Page copy protected against web site content infringement by Copyscape

About the Author

Full Name: Ambily KK
Member Level: Silver
Member Status: Member,Microsoft_MVP,MVP
Member Since: 5/18/2010 1:05:25 AM
Country: India
Thanks Ambily K K
I have over 9 years of experience working on Microsoft Technologies. I am carrying the passion on Microsoft technologies specifically on web technologies such as ASP .Net and Ajax. My interests also include Office Open XML, Azure, Visual Studio 2010. Technology adoption and learning is my key strength and technology sharing is my passion.

Login to vote for this post.

Comments or Responses

Login to post response

Comment using Facebook(Author doesn't get notification)