Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2015 - What does the "Analyzers" reference mean?

Creating a plain C# Console App in Visual Studio 2015 Preview, we get a pseudo reference named "Analyzers":


Expanded Solution Explorer project "References" showing "Analyzers" entry

What does the "Analyzers" reference just above mean?

The project file has nothing inside and the properties window shows nothing (completely blank) about this entry (though, in contrast to "reference properties" it says "folder properties" in the header, but that does not say much).

I would expect this to be related to Roslyn, but I have no idea. I have ReSharper installed, but I don't assume it has anything to do with it.

Edit 6.8.2016

The accepted answer explains the tooling provided by analyzers, but leaves open why a development tool becomes a (runtime?) reference. Actually it is not a runtime reference, unlike the other references. So the answer to this miracle is Hans Passants comment below:

They picked a clumsy place to add the code analyzers feature, they just couldn't find a better place without drastically overhauling the solution explorer and nuget. – Hans Passant May 26 '15 at 8:59

like image 742
citykid Avatar asked Jan 04 '15 11:01

citykid


People also ask

What is analyzers in Visual Studio?

NET Compiler Platform (Roslyn) Analyzers inspect your C# or Visual Basic code for style, quality, maintainability, design, and other issues. This inspection or analysis happens during design time in all open files. Analyzers are divided into the following groups: Code style analyzers are built into Visual Studio.

What are analyzers in .NET core?

ASP.NET Core provides an MVC analyzers package intended for use with web API projects. The analyzers work with controllers annotated with ApiControllerAttribute, while building on web API conventions. The analyzers package notifies you of any controller action that: Returns an undeclared status code.

What are .NET analyzers?

You can use code analyzers to find potential issues in your . NET Framework application code. The analyzers find potential issues and suggest fixes for them. Roslyn-based code analyzers run interactively in Visual Studio as you write your code or as part of a CI build.

How do I uninstall Visual Studio Analyzer?

To open this page, right-click the project node in Solution Explorer and select Properties. Select the Code Analysis tab. To disable source analysis at build time, uncheck the Run on build option. To disable live source analysis, uncheck the Run on live analysis option.


2 Answers

Live Code Analyzers are used to add custom error messages and warnings that appear live as you're typing, along with automatic code fixes to help you clean them up. They are available as NuGet packages that you add to your projects in Visual Studio 2015.

It is one of the best and helpful key new features of Visual Studio 2015 that lets a NuGet package enable custom warnings and errors in the editor live as you type the code, with automatic code fixes that can clean up those issues for us.

Packages can even be bundled together as a “code-aware library” that pulls in both an API and the domain-specific analyzers to make sure that you stay on course when using it.

We'll have a targeted guidance from the moment we download the NuGet package. And because these analyzers are part of our project, everyone on your team gets to see the same warnings.

Edit 1 :

Analyzers have rules attached to them like below :

enter image description here

These rules focus on the most critical problems in your code, including potential security holes, application crashes, and other important logic and design errors. You should include this rule set in any custom rule set you create for your projects.

like image 62
Tharif Avatar answered Oct 04 '22 10:10

Tharif


Currently there are a number of good Analyzers available – Microsoft.AnalyzerPowerPack, Code Cracker, CSharp Essentials, SonarLint etc

Each of these analyzers have their own rule set, so we can decide which analyzer to add, based on our requirements. Once installed via Nuget, the light bulbs and quick actions in VS2015 will pick up the associated rule set and provide the developers with coding assistance on the fly.

like image 30
Sammy Avatar answered Oct 04 '22 11:10

Sammy