StyleCop Cmd

StyleCop is a C# source code convention checker - a tool you can (and should) use to ensure that all the C# source code being written by your team is structured in a consistent and readable stye.

StyleCop Cmd is a simple commandline version, allowing you to integrate StyleCop with other build tools like NAnt and with continuous integration suites like CruiseControl.Net and TeamCity.

Released in May 2008 by Microsoft, it appears that StyleCop has been in internal use for some years. The Visual Studio integration is superb, as is the integration into MSBuild.

StyleCop.cmd is a simple command line driver that invokes the StyleCop SourceAnalysis engine to analyse C# source code.

The download is source code only - you'll have to compile it yourself with Visual Studio. Error handling is only rudimentary - plenty of room for improvement.

Not quite what you're looking for? Check out StyleCopCmd, an independent project with the same name (and similar intent) as this tool.

System Requirements

  • .NET 3.5 SDK or Runtime
  • StyleCop - download from Microsoft
  • Visual Studio 2008 - to compile the source.

Operation

Use the -settings flag to identify a Settings.SourceAnalysis file to control the analysis. If you omit this setting, the analysis engine will crash.

After -settings, pass the names of any files you want to analyse. If you list a .csproj file, all of the .cs files compiled by the project will be included for analysis.

Normal logging is to the console, but can be redirected to an xml file by the -xml option.

License

Source for StyleCop Cmd is under the MIT license. You are free to use and adapt the source in your own applications.

AttachmentSize
StyleCopCmd-1.2.2619.5171.zip30.47 KB

Comments

Hi,

I'd love to try your cmd line plugin for StyleCop, but it appears the download link is broken.

Found the problem and fixed things up. Sorry for the inconvenience.

Bevan.

Could not compile StyleCopCmd Project as its giving reference missing for assembly, Microsoft.SourceAnalysis. I have installed StyleCop 4.3.3.0 on my system. in that there don't exists any dll for Microsoft.SourceAnalysis.

Looking forward for your kind help.
Thanks and Regards,
Jackson C.

Hi Jackson.

Not sure what's going on - I'll have a look into this over the weekend and get back to you.

Between releases of StyleCop, the names of some assemblies, namespaces and classes have changed - instead of Microsoft.SourceAnalysis.dll, the assembly is now Microsoft.StyleCop.dll, and so on.

I've updated the StyleCop Cmd project to accomodate these changes - using StyleCop 4.4.

Hope this is helpful.

Hello,

I´m trying to build stylecop project but it is required Microsoft.SourceAnalysis?

Where can I find this libs?

--
Thank you in advance

Fernando Guedes Camargo
Special Projects, Inovation and Research

Cinq Technologies
www.cinq.com.br
+55 41 3091-2900
+55 41 9123-6091

Hi Fernando.

The StyleCopCmd project you see here is just a front end to Microsoft's own StyleCop product, intended to make it easier to use StyleCop within a Continuous Integration environment.

To compile my StyleCopCmd you need to download StyleCop from Microsoft as well.

Before you start using StyleCopCmd, I recommend you fully evaluate StyleCop to see if it meets your needs.

The original StyleCop is a free download from Microsoft here:
http://code.msdn.microsoft.com/sourceanalysis

Hope this helps,
Bevan.

hi,

Can anyone help me with setting up the StyleCopCmd with VS 2008?

I have already installed the following :

NET 3.5 SDK or Runtime
StyleCop - 4.3.3.0
Visual Studio 2008

how can I start the StyleCopCmd?

I have download the Zip file and build the code but I still dont get any output

in the cmd what is the exact command that needs to be run?

what I gave was :

 >cmd.cmd -settings MyProject.csproj  -xml


cmd.cmd will only open the start cmd.exe

can anyone help pls?

Thanks

pubu

Compiling StyleCop Cmd will give you the tool - look for StyleCopCmd.exe in the build output directory.

Copy the tool + supporting files into a folder, then you'll be able to run the tool over your own project.

Run StyleCopCmd.exe by itself (with no command-line flags) to see a summary of syntax.

IIRC, you'll want to do something like this:

stylecopcmd.exe myproj.csproj

Hope this is helpful,
Bevan.

Hi,

This looks great. I've not tried it yet (on my Linux laptop at the mo sat at the folks), was just wondering a few things.

Does it return error codes, ie an array of codes, or just 1 = fail?

I'm always playing around with our build at www.huddle.net, and like using NAnt. It would be handy to be able to fail the build if someone has committed bad code.

As currently written, it doesn't return any error code, as in my situation I didn't want to fail the build on the strength of a style issue.

However, you should find it pretty easy to add - just modify StyleCopDriver.Execute() to return a the count of violations in mViolations.

I may make this change myself, if I get the time - but would equally be happy to roll in a patch if you make the change yourself.

Keep Smiling,
Bevan.

I truly appreciate the hard word that went into creating it!

This is a great tool, thanks for taking the time to make it.

How would one go about getting this to work with TeamCity?

great tool.

whats the license for the source code?

and are you hosting it any source control? links for the source control if its possible.

I'm trying to create a task to run stylecop for albacore rakefiles. (http://github.com/derickbailey/Albacore)

Apologies for not specifying license terms - I've settled on the MIT license as it's very permissive. Let me know if that causes you any issues.

thanks.
i forked ur code and put it in github at https://github.com/prabirshrestha/StyleCopCmd
i also put stylecop dlls as local, so you don't need to install stylecop to use it. xcopy deployment.

You might want to check the StyleCop license to see if including the StyleCop assemblies directly in your project is allowed.

At the time I created StyleCopCmd, the license prohibited redistribution: including the assemblies in my download was not permitted, so I had to leave them out and tell people to download them themselves.

When I start this tool with such command line:
StyleCopCmd.exe -sf "MySolution.sln" -sc "Settings.StyleCop" -of "StyleCop.Report.xml"
It looks like it passes the settings file and use all the rules instead of pointed there. What is the way to make it to see the settings file?

As far as I know, you're doing it right.

For what it's worth, I keep my Settings.StyleCop file in the root directory of my solution. In this location, it's picked up automatically by the StyleCop engine, giving consistent results from different uses - such as by StyleCop for Resharper.

I'll have a look into this when I have some spare time - but in the interum, have a look at the source code and the documentation for StyleCop itself. If you do identify a bug in my code, I'd love to hear about it - and would naturally give you credit for the fix.

I have problem in creating stylecop exe in stylecop.

there is no output in your above given command line..after installing stylecop there is no stylecopcmd.exe file..