Code clone analysis tool in Visual Studio is used to find the duplicate section code in your solution. In this blog you will learn about how to install and use the code clone analysis tool to find a duplication section of code.
Visual Studio 2017/2019 Enterprise Edition.
This tool is available only in Enterprise edition.
Open Visual Studio installer, make sure the code clone under Individual components is installed. If not please enable and install it.
Code Clone Analysis Usage:
Open Visual studio and load your solution
Analyzing single line of code:
Select a line of code for which you need to find a duplication and do right click. From the list of menus select Find matching clones in solution, as shown in the below figure.
Now, you can select result and compare it with the original just by using the compare option by doing the right click as shown in below figure.
The above figure shows the comparison result between the selected files.
Analyzing the Solution:
So far, we have seen finding the duplication for selected lines, now let’s extend the analysis for complete solution.
From menu select Analyze -> Analyze solutions for Code Clones.
This will list out all the duplication code blocks in the solution. Based on the matching level it will categories as weak, medium, exact and strong match as shown in below figure.
Things we learned,
- How to install and the usage of code clone tool in Visual Studio.
- How to perform code line level and solution level analysis using the code clone tool.
I hope you have enjoyed this blog, your valuable feedback, questions, or comments about this blog are always welcome.