Live Static Code Analyzer for .NET and Azure


Live Static Code Analyzer Feature

In this article I will explain how to improve the code quality using visual studio tools. The tools include code analyzer , live static code analyzer and Azure static code analyzer . Code analyzers are the proven tools to improve the productivity and quality of your code. Code analyzer checks a set of rules while building the application and shows the warning messages for that. Developers can easily correct the code and follows the proper coding standards. We can even set a custom rule for each project . We can suppers any errors if not needed.

What is Live Static Code Analyzer ?

Live static code analyzers in Visual studio 2015 are similar to a normal code analyzers, but it finds the issues as you type even before you have finished the line. No more waiting to build the project. These analyzers are powered by modern .NET compiler platform called Roslyn . Live static code analyzer can automatically fix the issue through the new Visual studio bulb prompt.

Getting start with live static code analyzer demo

You can create your own code analyzer or you can use the existing analyzer like FxCop which is developed by the Microsoft Roslyn team. Third party analyzers also available like Code Cracker . For demo I’m going to use Code Cracker. Open the visual studio 2015 and create one project. Here I’m using ASP.NET MVC default template. Install Code Cracker from Nuget package using the following command.

install-package codecracker.csharp -pre

Then you can see our analyzer under the reference section in solution explorer. Expand CodeCracker.Csharp the you can see the set of rules.

Code Cracker Live Static Code Analyzer

Each rule starts with an icon . This icon based on the severity of the issue . We can change the rule severity by right clicking the rule and click on ‘set rule and set severity’ .

Live Static Code Analyzer - rule severity

Go to error list window, then you can see messages and warnings. Here I got 31 warnings and 43 messages . I took one random issue CC0068 ‘method is not used’. Click on the issue and you can see the nice bulb prompt on the method. If you click on Remove unused private method: ‘HasPhoneNumber’ then the method will be removed. There is also a suppress option to suppress the error without removing the method.

Live Static Code Analyzer with bulb prompt

Microsoft Code Analysis for Azure

Microsoft has a different code analyzer for azure . This package also in pre-release state with small set of code analysis rules. You can install it by entering following command.

Install-Package Microsoft.VisualStudio.Azure.CodeAnalysis -Pre
The following two tabs change content below.

Tom Mohan

Tom Mohan is a technologist who loves to code and build. He enjoys working on Microsoft Technologies. Tom specializes in ASP.NET MVC, Web API , Azure, C# ,WPF, SQL etc and holds a Bachelor engineering degree in Computer Science. Certification : MCSD , MCTS

Latest posts by Tom Mohan (see all)