Analyze csproj-File with StyleCop

Jul 14, 2010 at 9:44 AM

hey guys,

I know that it's not the primar objective of StyleCop but is there a way of analyzing / checking values of the *.csproj-Files of projects? Or maybe you know another way of doing this?!

thanks in advance,

claus

Jul 14, 2010 at 5:14 PM

Not today. This is conceivably possible if someone wants to do a little work. Since a csproj file is basically just an Xml file, this would involved creating a new StyleCop parser (similar to the CsParser class but much simpler) which is able to read Xml rather than C#. This could easily be done by using an XmlDocument or other Xml reader internally within the xml parser. This would then allow you to start plugging in new StyleCop rules which target that custom Xml parser.

From: hoffmeyster [mailto:notifications@codeplex.com]
Sent: Wednesday, July 14, 2010 1:45 AM
To: Jason Allor
Subject: Analyze csproj-File with StyleCop [stylecop:219393]

From: hoffmeyster

hey guys,

I know that it's not the primar objective of StyleCop but is there a way of analyzing / checking values of the *.csproj-Files of projects? Or maybe you know another way of doing this?!

thanks in advance,

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

Developer
Jul 14, 2010 at 8:08 PM

Hi,

It seems to me that StyleCop is not very suitable tool for doing things like this. When writing C# code, there are many principles that could be formulated as non-parametrized conditions.

When analysing project files, almost everything turns out to be parametrized - you are running csproj checks, passing different required parameters for each project, e.g.:

Project1

  • ProjectName = Project1
  • VisualStudioVersion = 2008
  • TargetPlatform = x86
  • TargetConfiguration = Release
  • DebugInfo = PdbOnly
  • ...

Project2

  • ProjectName = Project2
  • VisualStudioVersion = 2010
  • TargetPlatform = x64
  • TargetConfiguration = Debug
  • DebugInfo = Full
  • ... 

... so the purpose of such "project checker" will be mainly to check correctness of filling project properties, not some general things like identation or layout in C# code.

Of course there are some things that could be checked for every project, but often they are specific for you company or departament, e.g. in our company we are checking for so called "default configs", which have our own style. Another example is that you may have own "references principle" that you might want to check automatically.

All that I say is just my IMHO, but I am saying this because I have a huge experience in creating such "project checker" (now it checks more than a hundred of projects). And this expirience says that it is better to have custom own-written tool that checks all you want to check, in your own way. This tool could be also run as a part of your build process (or continious integration system).

Especially because there is really nothing difficult in parsing XML documents.

Best regards,
Oleg Shuruev

Jul 15, 2010 at 8:15 AM

Maybe it is an easy and good solution to create a XSD schema file and check the project file (XML) against it.

BTW, it would be great if StyleCop would support C++ as an additional programming language ;-)

Best regards,
Harald-René Flasch