Reputation: 18649
In starting to create a custom StyleCop rule I have followed the instructions on the Visual StyleCop Github.
• I've created a class, MyStyleCopRules.cs
:
[SourceAnalyzer(typeof(CsParser))]
public class MyStyleCopRules : SourceAnalyzer
{
public override void AnalyzeDocument(CodeDocument document)
{
...
• Added an XML document, with the build action set to EmbeddedResource, called 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>
Other possibly pertinent facts:
This library is building, in release, at Framework 3.5.
I have dropped a release build of this library in the same directory as StyleCop
I use StyleCop.MSBuild
(version 4.7.50) for the StyleCop integration, so I am copying it to \packages\StyleCop.MSBuild.{version}\tools
.
The version of StyleCop referenced within the library, is the same as the one I am copying it next to. (I have checked the versions using ILSpy.)
I am using Visual Studio 2015, but I am not using Analyzers
I don't see the rules when I open the Settings.StyleCop
file, nor do I see any indication that they run with Visual Studio
.
What have I missed?
Upvotes: 2
Views: 2505
Reputation: 18649
The Fully Qualified Using Statements
needs to have no spaces in it.
Namely:
<?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>
Upvotes: 1