I've included a 3rd party .cs file in my code. It doesn't comply with StyleCop's rules but I desperately need to be able to exclude it from StyleCop's checks but none of the methods I've found so far will work.
Three methods are documented here: http://sethflowers.com/blog/force-stylecop-to-ignore-a-file/ .. but none of these methods seems to work in StyleCop 4.7
The most useful of which looks to be this method in .csproj:
<Compile Include="AViolatingFile.cs">
<ExcludeFromStyleCop>true</ExcludeFromStyleCop>
</Compile>
But despite having added the files, StyleCop still causes a compilation error when parsing this file.
In your StyleCop install, there's a Settings. StyleCop file. You can edit this to turn off rules globally. Drag that file onto the Settings Editor executable in that file to edit it.
Configuring StyleCop is done in two optional steps. First, you can use rule set files to configure which rules are checked and how strongly you feel about them. Second, you can add a stylecop. json file to your project to fine-tune some rules.
// <auto-generated/>
Put this at the top of the class
Style cop ignores auto generated code
I used stylecop a while back as well and I believe you have to use the following line in your csproj file:
<Import Project="$(MSBuildExtensionsPath)\StyleCop\v4.6\StyleCop.targets" Condition="Exists('$(MSBuildExtensionsPath)\StyleCop\v4.6\StyleCop.targets')" />
You will also need to change the version number in the xml declaration to whatever you have installed.
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With