none
Reading Code Analysis RuleSet RRS feed

  • Question

  • I have written one code Activity for the automated build. We have to categorized code analysis build warnings. From the warning (IBuildWarning) property [Message], we get the Rule Code of the warning. But we need the complete details of the Rule. I googled it but was not able to find much resources on it.

    One Way was to  use

    var r = RuleSet.LoadFromFile(@"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\Rule Sets\BasicDesignGuidelineRules.ruleset");

    But we cannot hard code the path. Is there some Static or Global property of any class that we can use to get all the Rules.

    Thursday, June 21, 2012 9:59 AM

Answers

  • Hi Vikas,

    How about this path:

    Environment.SpecialFolder.ProgramFilesX86) + @"\Microsoft Visual Studio 11.0\Team Tools\Static Analysis Tools\Rule Sets\AllRules.ruleset"

    The folder structure is always like this : 

    \Microsoft Visual Studio 11.0\Team Tools\Static Analysis Tools\Rule Sets

    Or you can build a new rule set path environment varible like this:

    And then you can use it in your program like this:

    Console.WriteLine(Environment .GetEnvironmentVariable ("RuleSetPath"));

    I hope this will be helpful.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, June 22, 2012 8:32 AM
    Moderator

All replies

  • Hi Vikas,

    How about this path:

    Environment.SpecialFolder.ProgramFilesX86) + @"\Microsoft Visual Studio 11.0\Team Tools\Static Analysis Tools\Rule Sets\AllRules.ruleset"

    The folder structure is always like this : 

    \Microsoft Visual Studio 11.0\Team Tools\Static Analysis Tools\Rule Sets

    Or you can build a new rule set path environment varible like this:

    And then you can use it in your program like this:

    Console.WriteLine(Environment .GetEnvironmentVariable ("RuleSetPath"));

    I hope this will be helpful.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, June 22, 2012 8:32 AM
    Moderator

  • Thanks Mike for replying.

    I already tested with AllRules, It does not return any Rules. It works with BasicDesignGuidelineRules.ruleset.Is there some way that we can get All the Rules?


    //var r = RuleSet.LoadFromFile(@"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\Rule Sets\AllRules.ruleset");
    //var r = RuleSet.LoadFromFile(@"BasicDesignGuidelineRules.ruleset");
    var r = RuleSet.LoadFromFile(@"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\Rule Sets\BasicDesignGuidelineRules.ruleset");



    Monday, June 25, 2012 5:29 AM
  • Suppose Rule Id is CA1000 and Name is "Do not declare static members on generic types".

    But in the RuleReference object, we do not get any Name or description field. I need Rule Id + Rule Description.

    Is there some way we can get both of these values?

    Monday, June 25, 2012 5:58 AM

  • Thanks Mike for replying.

    I already tested with AllRules, It does not return any Rules. It works with BasicDesignGuidelineRules.ruleset.Is there some way that we can get All the Rules?


    //var r = RuleSet.LoadFromFile(@"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\Rule Sets\AllRules.ruleset");
    //var r = RuleSet.LoadFromFile(@"BasicDesignGuidelineRules.ruleset");
    var r = RuleSet.LoadFromFile(@"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\Rule Sets\BasicDesignGuidelineRules.ruleset");



    Hi Vikas,

    I just use a file named "AllRules.ruleset", if this confused you, I would change it back to your test file: "BasicDesignGuidelineRules.ruleset".

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, June 25, 2012 6:54 AM
    Moderator
  • Hi Vikas,

    As I said, you can try to make a environment variable. All the ruleset files is in that folder, so you can load them in that path.

    http://msdn.microsoft.com/en-us/library/wz42302f.aspx 

    Directory.GetFiles("path","*.ruleset") 

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, June 25, 2012 6:59 AM
    Moderator