Create Custom Rules

May 23, 2011 at 9:45 PM

Hi,

I need to develop some custom rules for StyleCop. We did this already with version 4.3. Now I use VS 2010 C# Express, Windows 7 and StyleCop 4.4. I created a new project (class library) with only one class and the corresponding  xml file (embedded ressource). I copied the CustomStyleCopRules.dll to the directory where Microsoft.StyleCop.dll is located. After that I started Settings.StyleCop, but there are only appear the standard StyleCop rules. I use 3 different PC's (2 XP with different Studio Versions). On all PC I don't get the Custom Ruleset work.

Can someone of you give me a hint, what I'm doing wrong?

I uploaded my Visual Studio 2010 project here https://rapidshare.com/files/717277114/CustomStyleCopRules.zip

Hopefully this helps to analyze the problem.

regards,

mathias

Developer
May 24, 2011 at 4:55 AM

Hi Mathias,

1. Your analyzer class name should be "CustomRules", but now it is "AccessModifiers".

2. Your CustomRules.xml file should have Build Action "Embedded Resource", but now it is "Content".

3. I would also recommend you upgrading to StyleCop 4.5.

Best regards,
Oleg Shuruev

May 24, 2011 at 6:09 PM

Hi,

thx for the tip. I uploaded a bad project, but your comments were correct. It worked only with the new stylecop version.

regards,

mathias

May 25, 2011 at 6:50 PM

Hi,

unfortunately the client i work for, does not like beta versions. So I need to get it work with StyleCop 4.4.0.14. I created a simple Projekt which works with StyleCop 4.5. Why does this not work for 4.4? I uploaded a new version with references to 4.4. Can someone help, please? The rules are not shown in StyleCop if I start the Settings.StyleCop Editor. This worked fine with 4.5.

https://rapidshare.com/files/4112553137/StyleCopCustomRules.zip

 

greetz,

mattes

Coordinator
May 25, 2011 at 6:52 PM

I can call the 4.5RC 4.5RTW if that helps? 4.5RC is much more stable than 4.4 or 4.3 (over 200 bugs fixed).

May 25, 2011 at 7:58 PM

this could help i guess. on the other hand it would be very interesting, why it does not work with 4.4. I created rules some years ago and it worked with 4.3, but even with this version, my simple project does not work.

Developer
May 25, 2011 at 10:06 PM

BTW, the file you attached works fine for 4.4.0.14.

Best regards,
Oleg Shuruev

May 26, 2011 at 4:56 PM
shuruev wrote:

BTW, the file you attached works fine for 4.4.0.14.

Best regards,
Oleg Shuruev

hey, you're right. The main point to get it work, copy the dll to the correct location. In Program Files/Microsoft StyleCop 4.4.0.14 it does not work. Under Program Files/MSBuild/... it works. :-)

Thx for your support.

Developer
May 27, 2011 at 9:37 AM

So as you can see, even now you dealt with "double SettingEditor" bug, which is only one of 200 bugs Andy mentioned.

Wish you good luck and a speedy migration to 4.5.

Best regards,
Oleg Shuruev

May 27, 2011 at 3:32 PM

you're so right. personally i use 4.5 on my laptop. the client still uses 4.4, but it's ok for now. we started just with some simple metrics.

May 27, 2011 at 3:48 PM

4.5 seems to have a new bug though too. Or I am missing something.

http://stylecop.codeplex.com/discussions/259267