Visual Studio 2015 - “分析器"有什么作用?参考是什么意思? [英] Visual Studio 2015 - What does the "Analyzers" reference mean?

查看:73
本文介绍了Visual Studio 2015 - “分析器"有什么作用?参考是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Visual Studio 2015 Preview 中创建一个普通的 C# 控制台应用程序,我们得到一个名为Analyzers"的伪引用:

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


上面提到的分析器"是什么意思?

项目文件里面什么都没有,属性窗口没有显示关于这个条目的任何内容(完全空白)(尽管与参考属性"相反,它在标题中说文件夹属性",但这并没有说明太多).

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

我希望这与 Roslyn 有关,但我不知道.我安装了 ReSharper,但我不认为它与它有任何关系.

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.

编辑 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:

他们选择了一个笨拙的地方来添加代码分析器功能,如果不彻底检修解决方案资源管理器和 nuget,他们就找不到更好的地方.– 汉斯·帕桑特 15 年 5 月 26 日 8:59

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

推荐答案

实时代码分析器 用于添加在您键入时实时显示的自定义错误消息和警告,以及自动代码修复帮助您清理它们.它们以 NuGet 包的形式提供,您可以将它们添加到 Visual Studio 2015 中的项目中.

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.

这是 Visual Studio 2015 中最好和有用的关键新功能之一,它允许 NuGet 包在您键入代码时在编辑器中实时启用自定义警告和错误,自动代码修复可以为我们清理这些问题.

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.

包甚至可以捆绑在一起作为代码感知库",它同时引入 API 和特定于域的分析器,以确保您在使用它时始终如一.

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.

从下载 NuGet 包的那一刻起,我们就会有针对性的指导.由于这些分析器是我们项目的一部分,您团队中的每个人都会看到相同的警告.

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.

分析器附有如下规则:

这些规则专注于代码中最关键的问题,包括潜在的安全漏洞、应用程序崩溃和其他重要的逻辑和设计错误.您应该将此规则集包含在您为项目创建的任何自定义规则集.

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.

这篇关于Visual Studio 2015 - “分析器"有什么作用?参考是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆