Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can you force StyleCop to ignore a file?

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.

like image 626
NickG Avatar asked May 30 '13 16:05

NickG


People also ask

How do you change rules on StyleCop?

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.

How do you implement StyleCop?

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.


2 Answers

// <auto-generated/> 

Put this at the top of the class

Style cop ignores auto generated code

like image 123
user2627366 Avatar answered Oct 15 '22 15:10

user2627366


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.

like image 20
Rob Aston Avatar answered Oct 15 '22 15:10

Rob Aston