安装自定义 StyleCop 规则
Installing Custom StyleCop Rule
在开始创建自定义 StyleCop 规则时,我遵循了 Visual StyleCop Github 上的说明。
• 我创建了 class、MyStyleCopRules.cs
:
[SourceAnalyzer(typeof(CsParser))]
public class MyStyleCopRules : SourceAnalyzer
{
public override void AnalyzeDocument(CodeDocument document)
{
...
• 添加了 XML 文档,构建操作设置为 EmbeddedResource,名为 MyStyleCopRules.xml
:
<?xml version="1.0" encoding="utf-8" ?>
<SourceAnalyzer Name="My StyleCop Rules">
<Rules>
<Rule Name="Fully Qualified Using Statements" CheckId="IS0001">
<Context>Using statements must be fully qualifed.</Context>
<Description>Fires when using statements are not fully qualifed.</Description>
</Rule>
</Rules>
</SourceAnalyzer>
其他可能相关的事实:
此库正在 Framework 3.5 版本中构建。
我已将此库的发布版本删除到与 StyleCop 相同的目录中
我使用 StyleCop.MSBuild
(版本 4.7.50)进行 StyleCop 集成,所以我将其复制到 \packages\StyleCop.MSBuild.{version}\tools
。
库中引用的 StyleCop 版本与我在旁边复制的版本相同。 (我已经使用 ILSpy 检查了版本。)
我正在使用 Visual Studio 2015,但我没有使用 Analyzers
我打开 Settings.StyleCop
文件时没有看到规则,也没有看到任何迹象表明它们 运行 和 Visual Studio
。
我错过了什么?
Fully Qualified Using Statements
中不能有空格。
即:
<?xml version="1.0" encoding="utf-8" ?>
<SourceAnalyzer Name="My StyleCop Rules">
<Rules>
<Rule Name="FullyQualifiedUsingStatements" CheckId="IS0001">
<Context>Using statements must be fully qualifed.</Context>
<Description>Fires when using statements are not fully qualifed.</Description>
</Rule>
</Rules>
</SourceAnalyzer>
在开始创建自定义 StyleCop 规则时,我遵循了 Visual StyleCop Github 上的说明。
• 我创建了 class、MyStyleCopRules.cs
:
[SourceAnalyzer(typeof(CsParser))]
public class MyStyleCopRules : SourceAnalyzer
{
public override void AnalyzeDocument(CodeDocument document)
{
...
• 添加了 XML 文档,构建操作设置为 EmbeddedResource,名为 MyStyleCopRules.xml
:
<?xml version="1.0" encoding="utf-8" ?>
<SourceAnalyzer Name="My StyleCop Rules">
<Rules>
<Rule Name="Fully Qualified Using Statements" CheckId="IS0001">
<Context>Using statements must be fully qualifed.</Context>
<Description>Fires when using statements are not fully qualifed.</Description>
</Rule>
</Rules>
</SourceAnalyzer>
其他可能相关的事实:
此库正在 Framework 3.5 版本中构建。
我已将此库的发布版本删除到与 StyleCop 相同的目录中
我使用
StyleCop.MSBuild
(版本 4.7.50)进行 StyleCop 集成,所以我将其复制到\packages\StyleCop.MSBuild.{version}\tools
。库中引用的 StyleCop 版本与我在旁边复制的版本相同。 (我已经使用 ILSpy 检查了版本。)
我正在使用 Visual Studio 2015,但我没有使用 Analyzers
我打开 Settings.StyleCop
文件时没有看到规则,也没有看到任何迹象表明它们 运行 和 Visual Studio
。
我错过了什么?
Fully Qualified Using Statements
中不能有空格。
即:
<?xml version="1.0" encoding="utf-8" ?>
<SourceAnalyzer Name="My StyleCop Rules">
<Rules>
<Rule Name="FullyQualifiedUsingStatements" CheckId="IS0001">
<Context>Using statements must be fully qualifed.</Context>
<Description>Fires when using statements are not fully qualifed.</Description>
</Rule>
</Rules>
</SourceAnalyzer>