locked
How to Run StyleCop Automatically After Build? RRS feed

  • Question

  • I have installed StyleCop and I can run it manually using the Tools menu in VS. I'd want to run StyleCop automatically after my class library project is built.

    Do you know any macro that can be placed in the "Port-Build Event" section of my Project Properties page which would make the StyleCop run?

    I placed this macro:
    "%ProgramFiles%\Microsoft StyleCop 4.3.2.1\StyleCopSettingsEditor.exe" "$(ProjectDir)/Settings.StyleCop"

    But it only opens the StyleCop rule management window without really running it.

    Any thoughts?

    Thanks,

    Saturday, November 14, 2009 9:49 AM

Answers

  • Found this very helpful. Unfortunately I have to modify all my projects inside the solution. If I could just make a change in the .sln file and it could do the job, that would be great but don't know whether it's possible.
    • Marked as answer by Dynamic Wednesday, November 25, 2009 6:06 PM
    Saturday, November 14, 2009 10:46 AM
  • Visual Studio Code Analysis is essentially a Visual Studio-integrated version of FxCop.  StyleCop is an entirely different beastie that analyzes source code instead of compiled assemblies.

    • Marked as answer by liurong luo Wednesday, November 18, 2009 2:17 AM
    Tuesday, November 17, 2009 6:45 PM
  • The target of FxCop and StyleCop is different. FxCop targets at compiled data, it analzes the MSIL code while StyleCop targets at the source code (not compiled). Hence, if we want to check the source code, we'd better choose StyleCop, however, if we want to analze the MSIL code, FxCop will be you best bet. Which one to choose is up to ourselves.

    Best regards


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have any feedback, please tell us.
    Welcome to the All-In-One Code Framework!
    • Marked as answer by liurong luo Wednesday, November 18, 2009 2:17 AM
    Wednesday, November 18, 2009 2:16 AM

All replies

  • Found this very helpful. Unfortunately I have to modify all my projects inside the solution. If I could just make a change in the .sln file and it could do the job, that would be great but don't know whether it's possible.
    • Marked as answer by Dynamic Wednesday, November 25, 2009 6:06 PM
    Saturday, November 14, 2009 10:46 AM
  • Hello,

    Thanks for your post and the additional information, well done!
    On my opinion, it's not proper to run StyleCop on eavh project in the solution. This is because StyleCop is target at C# source code, however, there maybe various types of projects in our solution besides C# projects. For more discussion about StyleCop, please refer to:
    http://code.msdn.microsoft.com/sourceanalysis/Thread/List.aspx

    Best regards,
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have any feedback, please tell us.
    Welcome to the All-In-One Code Framework!
    Monday, November 16, 2009 10:37 AM
  • The .sln file does not contain any build configuration information.  However, you can create a common MSBuild targets file that is included in your project files by reference.  If you create one that is intended for inclusion in only your C# projects, this would also avoid the problem mentioned by Roahn wrt StyleCop targeting only C#.

    Monday, November 16, 2009 2:08 PM
  • Is Visual Studio Code Analysis Tool the same as StyleCop, FxCop, Both or neither?!
    Tuesday, November 17, 2009 5:41 PM
  • Visual Studio Code Analysis is essentially a Visual Studio-integrated version of FxCop.  StyleCop is an entirely different beastie that analyzes source code instead of compiled assemblies.

    • Marked as answer by liurong luo Wednesday, November 18, 2009 2:17 AM
    Tuesday, November 17, 2009 6:45 PM
  • Thanks.

    I read that FxCop has some overlapping rules with StyleCop such as Naming Conventions.

    Which one do you usually configure to use for your application? VS Code Analysis + StyleCop?
    • Marked as answer by Dynamic Wednesday, November 25, 2009 6:06 PM
    • Unmarked as answer by Dynamic Wednesday, November 25, 2009 6:06 PM
    Tuesday, November 17, 2009 7:32 PM
  • The target of FxCop and StyleCop is different. FxCop targets at compiled data, it analzes the MSIL code while StyleCop targets at the source code (not compiled). Hence, if we want to check the source code, we'd better choose StyleCop, however, if we want to analze the MSIL code, FxCop will be you best bet. Which one to choose is up to ourselves.

    Best regards


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have any feedback, please tell us.
    Welcome to the All-In-One Code Framework!
    • Marked as answer by liurong luo Wednesday, November 18, 2009 2:17 AM
    Wednesday, November 18, 2009 2:16 AM
  • I usually use both FxCop (or VS Code Analysis, depending on whether a VS edition that includes it is available to all developers on a project) and StyleCop.  If StyleCop happens to check something that FxCop also checks, that's no big deal.  If scanning times are a concern, and you don't want to take the hit of double-scanning for the same problem, I would recommend disabling an overlapping rule in StyleCop instead of in FxCop since FxCop will work for code written in any language, but StyleCop can only scan C# code (at least for now).
    Wednesday, November 18, 2009 12:43 PM