简体   繁体   English

StyleCop 4.7是否与C#6.0代码兼容

[英]Is StyleCop 4.7 compatible with C# 6.0 code

I installed StyleCop 4.7 for developing customized rules, to analyze our C# code. 我安装了StyleCop 4.7来开发自定义规则,以分析我们的C#代码。

We write the code in Visual Studio 2015. I can analyze my C# 5.0 (Visual Studio 2013) code, and I get correct response, but when I analyze my C# 6.0 (Visual Studio 2015) code, StyleCop raises an exception for my rules. 我们在Visual Studio 2015中编写代码。我可以分析我的C#5.0(Visual Studio 2013)代码,并得到正确的响应,但是当我分析我的C#6.0(Visual Studio 2015)代码时,StyleCop会为我的规则引发异常。

Now my question is: 现在我的问题是:

Is StyleCop 4.7 compatible with C# 6.0 code? StyleCop 4.7与C#6.0代码兼容吗? If not, do we have any solution? 如果没有,我们有解决方案吗?

TL;DR - Yes. TL; DR - 是的。 StyleCop 4.7 was updated to be compatible with C# 6 starting with 4.7.51 (Beta) released on 13th March 2016. StyleCop 4.7已更新为与2016年3月13日发布的4.7.51(Beta)开始的C#6兼容。
There was a handover to new custodians back in January 2016, and a new version 4.7.50 alpha has been released 3rd Feb 2016, but as yet does not include C# 6 support. 2016年1月有新的托管人移交, 2016年2月3日发布了新的4.7.50 alpha版本,但尚未包含C#6支持。
4.7.51 (Beta) was released on 13th March 2016 and the latest stable is 4.7.54 released May 13th. 4.7.51(Beta)于2016年3月13日发布,最新稳定版本为5月13日发布的4.7.54。


Here are three other options that work with Visual Studio 2015: 以下是与Visual Studio 2015一起使用的其他三个选项:

1. Visual StyleCop 1.视觉StyleCop

Visual StyleCop , is an extension to Visual Studio. Visual StyleCop是Visual Studio的扩展。 This gives you the right click functionality into Visual Studio 2015 that installing StyleCop gave you for 2013 and below. 这为您提供了Visual Studio 2015中的右键单击功能,安装StyleCop为您提供2013及以下版本。

This is available by adding an extension into Visual Studio: 这可以通过在Visual Studio中添加扩展来实现:

Visual StyleCop

It is an active project and will give you StyleCop on C# 6 features. 这是一个活跃的项目,将为您提供C#6功能的StyleCop。 There is a package - Visual-StyleCop.MSBuild , that will give you MSBuild integration. 有一个包 - Visual-StyleCop.MSBuild ,它将为您提供MSBuild集成。

It is possible to write custom rules with Visual StyleCop. 可以使用Visual StyleCop编写自定义规则

2. StyleCop Analyzers 2. StyleCop分析仪

StyleCop.Analyzers are built upon Rosalyn and make use of the Analyzers feature of Visual Studio 2015. They are available on NuGet: StyleCop.Analyzers构建于Rosalyn之上,并利用Visual Studio 2015的分析器功能。它们可在NuGet上获得:

StyleCop.Analyzers NuGet包

This would add them into the rules in the relevant *.ruleset file (same place as CodeAnalysis rules, accessible from the project page:) 这会将它们添加到相关*.ruleset文件中的规则中(与CodeAnalysis规则相同,可从项目页面访问:)

项目页面

giving: 赠送:

RuleSet示例

and you can run them via 你可以通过它来运行它们

运行分析器示例

Which has the same effect as right click, Run StyleCop , used on previous versions and with Visual StyleCop. 其效果与右键单击, Run StyleCop相同 ,在以前的版本和Visual StyleCop中使用。

Giving: 赠送:

示例错误

The source code is available on GitHub , so adding custom rules should be possible. 源代码在GitHub上可用 ,因此应该可以添加自定义规则。

3. Resharper, with StyleCop by Jetbrains 3.Resharper,Jetbrains的StyleCop

Install: 安装:

  • Resharper 10.0.1 Resharper 10.0.1
  • StyleCop by JetBrains 4.8 StyleBop by JetBrains 4.8

R#StyleCop插件

Which gives this in R# options: 这在R#选项中给出了这个: R#选项

This gives you syntax highlighting, but no right click run, and no build integration. 这为您提供了语法突出显示,但没有右键单击运行,也没有构建集成。 Additionally, R# is not a free product. 此外,R#不是免费产品。

You can extend it using plugins, but it doesn't feel as customizable as the other two options presented. 您可以使用插件扩展它,但它不像其他两个选项那样可以自定义。

Version 4.7.51 and later should support C# 6: 版本4.7.51及更高版本应支持C#6:

Added initial (and untested) support for C# 6.0 syntax 添加了对C#6.0语法的初始(和未经测试)支持

http://stylecop.codeplex.com/releases/view/620339 http://stylecop.codeplex.com/releases/view/620339

So the current stable build should support it, too: http://stylecop.codeplex.com/releases 所以当前稳定版本也应该支持它: http//stylecop.codeplex.com/releases

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM