Chapter 9. Code Analysis Beyond Visual Studio

ReSharper v8 comes with brand new, free command-line tools to run code analysis outside Visual Studio.

The tools come as a compressed package. To download them, go to the Download ReSharper page at http://www.jetbrains.com/resharper/download/ and click on ReSharper Command Line Tools in the Related Downloads section. When you unpack this package, you will find many .dll files in there that come from ReSharper and also the following two important .exe files:

  • dupfinder.exe: This finds code duplicates
  • inspectcode.exe: This runs code analysis

In this chapter, we will quickly describe these applications.

Finding code duplicates

The first tool, dupfinder, can be used to find duplicates in your C# and VB.NET code. What is really cool is that it not only marks some parts of your code as duplicated if they are identical, but also if they have a similar structure. This means that even if two parts of your code contain different variable names or methods, they can be, in a very smart way, marked as duplicated.

To run dupfinder, use the following command:

dupFinder [OPTIONS] source

The source parameter specifies what you would like to analyze. It can be a solution file or just files from your projects. A sample file path would look as follows:

dupfinder.exe E:ctv_projectcodingblog	runksrcCodingBlog.sln
dupfinder.exe E:ctv_projectcodingblog	runksrc***.cs

At the end, dupfinder will inform you of how many files have been analyzed and where the report has been created through the following output:

26 files found to analyze.
INFO: Duplicates report was written to C:UsersLukaszAppDataLocalTemp	mp9D32.tmp

By default, it is saved in the Temp folder, but you can change this with the /output option.

For more options that you can use with dupfinder, run the following command:

dupfinder /help

With additional options, you can exclude some files, check CPU usage and memory statistics, use debug messages, include duplicated code, and more.

A sample report is shown in the following screenshot:

Finding code duplicates

As it is available as an XML file, you can use an XSL transformation to convert it into an HTML report or use any custom tool to prepare the required report.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.116.49.247