Integrated StyleCop - But always "No violations encountered"

Jul 22, 2010 at 7:34 AM

My task is it to integrate StyleCop and pass files to analyze to it. So far i managed it but the problem is that I always get the message "No violations encountered". If i check it in Visual Studio i get all the warnings so I think that it is a problem with the Settings.StyleCop - File.

That's the line how i instantiate the StyleCopConsole:

StyleCopConsole console = new StyleCopConsole(Settings.DefaultFileName, true, null, null, true);

I also tried already with an absolute path to an Settings-File (instead of "Settings.DefaultFileName") but it did not change anything :(

I hope someone can help me :)

Thanks in advance,
Claus

Developer
Jul 22, 2010 at 3:10 PM

Hi,

You could check out the simpliest example for running StyleCop from your code:
http://stylecopplus.codeplex.com/wikipage?title=Running%20StyleCop%20from%20Your%20Code

Best regards,
Oleg Shuruev

Jul 23, 2010 at 6:07 AM

hi oleg,

for your reply and the sample. as i mentioned i got it somehow to work but i think the problem is the settings.stylecop - file cause i always get the message "no violations encountered". in the stylecopconsole-constructor i tried to path an absolute path and i tried it with an relative path and i tried with a null-value (like in the sample) but i didn't change anything :-/

best regards
claus

Jul 23, 2010 at 8:15 AM

so, now i got the sample working "local" - that means if i make a console-application with your code it works fine. but what i want to do is to run it out of a webservice. that means i have an webservice listening for a checkin-event on a tfs. the triggering works fine but here i still get "no violations encountered" :-/

best regards
claus

Developer
Jul 23, 2010 at 8:58 AM

1. In my example I pass null for settings file to StyleCopConsole constructor because I want the settings file to be chosen by StyleCop.
http://stylecop.codeplex.com/wikipage?title=Settings%20Files%20tab&referringTitle=Settings

If you don't know what settings was applied to your project, I would recommend add a "debug" code that will show actual settings for your project after it has been checked.

2. I wonder why you are using webservice. Checking you've menitoned could be a part of your build process. Then it would be a console application that runs inside the build sequence, checks whatever you want, sends e-mails whereever you want, and fails the build if needed.

Best regards,
Oleg Shuruev

 

Jul 23, 2010 at 9:04 AM

thanks again for your fast replay! i think the settings-problem is solved for me so far...

hm, actually we want to check the files after they got checked in. and with a webservice i get a method triggered after somebody checked-in something... this works fine. but then, if i call the method for checking it, it always says "no violations encountered"...
but maybe we though have to make it within the build-process if i can't find a solution :-/

best regards,
claus

Jul 23, 2010 at 12:16 PM

Now I found out what the "real problem" is. If i run the methode from the WebService the method "AddSourceCode" always returns false :-/ ... i can run it with the exactly same pathes one time from the console application (it works) and one time from the WebService (it does not work!). little bit weird for me, but maybe someone has an idea :)

best regards,
claus

Jul 23, 2010 at 7:37 PM

No idea. Maybe you could grab the source off of codeplex and debug?

From: hoffmeyster [mailto:notifications@codeplex.com]
Sent: Friday, July 23, 2010 4:17 AM
To: Jason Allor
Subject: Re: Integrated StyleCop - But always "No violations encountered" [stylecop:220546]

From: hoffmeyster

Now I found out what the "real problem" is. If i run the methode from the WebService the method "AddSourceCode" always returns false :-/ ... i can run it with the exactly same pathes one time from the console application (it works) and one time from the WebService (it does not work!). little bit weird for me, but maybe someone has an idea :)

best regards,
claus

Read the full discussion online.

To add a post to this discussion, reply to this email (stylecop@discussions.codeplex.com)

To start a new discussion for this project, email stylecop@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

Jul 26, 2010 at 8:17 AM

hi jasonall,

i already grabbed the source and tried to debug... it got the project loading correct into VS 2010, but now i don't know how to debug, cause i am calling the assembly from a webservice. already tried to change the Debug-Property "Start Action" to "Start browser with URL" and type-in the URL of the webservice but it still does not stops at any breakpoint... :-/

best regards,
claus

 

Jul 26, 2010 at 3:13 PM

Hm, now i know exactly where the problem is... the method "AddSourceCode(...)" always returns false, when i run it from the webservice, if i run it form the console it works properly...

Apr 6, 2011 at 6:14 AM

Now I'm stuck with the same issue. Always seeing "no violations"
As shown here
1. AddSourceCode(..) - always returns false
2. SourceFilesList in console.Core.Environment.GetSettings(styleCopSettingsFilePath,false) is always 0.

Please suggest if there are any workarounds.

Thanks!!

Jul 12, 2011 at 7:45 AM
Edited Jul 12, 2011 at 8:26 AM

I'm guessing you're missing assembly references to StyleCop.CSharp.dll and StyleCop.CSharp.Rules.dll. I believe these are dynamically discovered at runtime so StyleCop will report no violations if it does not find any rules to apply to your source. When I call StyleCopConsole.Core.Environment.AddSourceCode in a custom TFS workflow CodeActivity I also get false but this does not seem to have any impact on StyleCopConsole's ability to run its analysis.

Don

Jun 13, 2012 at 7:22 AM
Codeplex12345 wrote:

I'm guessing you're missing assembly references to StyleCop.CSharp.dll and StyleCop.CSharp.Rules.dll. I believe these are dynamically discovered at runtime so StyleCop will report no violations if it does not find any rules to apply to your source. When I call StyleCopConsole.Core.Environment.AddSourceCode in a custom TFS workflow CodeActivity I also get false but this does not seem to have any impact on StyleCopConsole's ability to run its analysis.

Don


This solved the problem for me also.

Sep 23, 2014 at 4:03 PM
Edited Sep 23, 2014 at 4:03 PM
Codeplex12345 wrote:
I'm guessing you're missing assembly references to StyleCop.CSharp.dll and StyleCop.CSharp.Rules.dll. I believe these are dynamically discovered at runtime so StyleCop will report no violations if it does not find any rules to apply to your source. When I call StyleCopConsole.Core.Environment.AddSourceCode in a custom TFS workflow CodeActivity I also get false but this does not seem to have any impact on StyleCopConsole's ability to run its analysis. Don
I have same problem. But your solution didn't solve it. Can anyone help me?