"No rules were Selected" error is coming in FxCop 10.0 while I am running my own Custom rule on a .exe(executable file) which I added in Targets.

Locked "No rules were Selected" error is coming in FxCop 10.0 while I am running my own Custom rule on a .exe(executable file) which I added in Targets.

  • Friday, March 09, 2012 10:19 AM
     
     
     

    Initially I want to develop a Custom Rule on my own for FxCop 10.0.

    So, I had taken a Class Library in VisualStudio2010 with NameSpace CheckingNameSpaces2.

    I added a Rules.XML file to it.

    <?xml version="1.0" encoding="utf-8" ?>

    <Rules>

      <Rule TypeName="CheckForValidNamespaceNamingConvention" Category="NamingConvention" CheckId ="ID1">

        <Name>check for valid namespacenaming convention</Name>

        <Description>every namespace should start with prefix “MyCompanyName.Projectname.Modulename.”</Description>

        <Resolution>change the name of the namespace ‘{0}’ to start with prefix       'MyCompanyName.Projectname.Modulename.'</Resolution>

        <Messagelevel Certainity="99">warning</Messagelevel>

        <Message Certainity="99"></Message>

        <Fixcategories>nonbreaking</Fixcategories>

        <Owner></Owner>

        <Url></Url>

        <Email></Email>

      </Rule>

    </Rules>

    Then I coded in C#.net like below after adding the references FxCopSdk.dll, Micorosoft.Cci.dll

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Text;

    using Microsoft.FxCop.Sdk;

    namespace CheckingNameSpaces2

    {  

        public class CheckForValidNamespaceNamingConvention: BaseIntrospectionRule

        {

            public CheckForValidNamespaceNamingConvention() :

                base("CheckForValidNamespaceNamingConvention", "CheckingNameSpaces2.Rules",

               typeof(CheckForValidNamespaceNamingConvention).Assembly)

            {

            }

           

            public override ProblemCollection Check(TypeNode type)

            {

                if (!type.Namespace.Name.StartsWith("MyCompanyName.Projectname.Modulename."))

                {

                    Problem problem = new Problem(GetResolution(new object[] { type.Namespace.Name }));

                    base.Problems.Add(problem);

                }

                return base.Problems;

            }

        }

    }

    I browsed this CheckingNameSpaces2.ddl in FxCop10.0 from AddRules option.

    Now when I take a Target and executed my Rule on it, it is giving  error "No rules were selected".

    I was concerned because after adding the rule it is not giving a subnode under ChekingNameSpace2.dll. 

All Replies

  • Friday, March 09, 2012 1:19 PM
     
     
    Is the build action for your Rules.xml file set to "Embedded Resource"?  If so, have you confirmed the name of the resulting embedded resource in the compiled DLL?  (You can use ildasm or Reflector or some other similar tool for this.)
  • Friday, March 09, 2012 1:29 PM
     
     

    Hi Nicole Thanks for your answer,

    I marked the property of XML as "Embedded Resource".

    You are speaking something about confirmation of the name. Can you explain it clearly.

  • Friday, March 09, 2012 2:22 PM
     
     

    The second argument of your call to the BaseIntrospectionRule constructor must match the name of the embedded rules resource in the compiled assembly (minus the ".xml" extension).  If you provide an incorrect name, FxCop can't find the embedded resource, and it won't load the rule.

    Nicole

  • Monday, March 12, 2012 3:05 AM
     
     
    I did that also...You can have a look at the code to verify once.
  • Monday, March 12, 2012 1:13 PM
     
     Answered Has Code

    In that case, you might want to check that your rule description XML is actually valid.  What you've pasted into the original post in this thread isn't.  For example, the Messagelevel and Fixcategories element names are mis-cased, the Certainity attribute name is mis-spelled, and there shouldn't be a Message element.  Try this instead:

    <?xml version="1.0" encoding="utf-8" ?>
    <Rules FriendlyName="Custom Rules">
    	<Rule TypeName="CheckForValidNamespaceNamingConvention" Category="NamingConvention" CheckId ="ID1">
    		<Name>check for valid namespacenaming convention</Name>
    		<Description>every namespace should start with prefix “MyCompanyName.Projectname.Modulename.”</Description>
    		<Resolution>change the name of the namespace ‘{0}’ to start with prefix 'MyCompanyName.Projectname.Modulename.'</Resolution>
    		<MessageLevel Certainty="99">Warning</MessageLevel>
    		<FixCategories>NonBreaking</FixCategories>
    		<Owner></Owner>
    		<Url></Url>
    		<Email></Email>
    	</Rule>
    </Rules>

  • Sunday, March 18, 2012 5:53 AM
     
     Answered

    Hi Nicol,

    Will definitly try your XML and thanks for your post.

  • Monday, March 19, 2012 2:13 AM
    Moderator
     
     Answered

    Hi Shiva,

    I mark the answer, please check it. If you need further assistance, please feel free to let us know.

    Best Regards,



    Jack Zhai [MSFT]
    MSDN Community Support | Feedback to us

  • Monday, March 19, 2012 7:05 AM
     
     

    Hi Jack and Nicol,

    I thank you both, now I am able to execute my own custom rule. Thanks for your help

    Regards,

    Siva

  • Friday, March 30, 2012 1:20 AM
     
     

    Hi,

    Prior to all these errors. Initially I wrote my Custom Rule in VS 2010. Then I tried to Integrate in FxCop 1.36. It throwed some versioning error because VS 2010 is using .NET Framework 4.0.

    Then I  changed the .NET Framework to 3.5 for the same code from project options, and tried to Integrate in FxCop 1.36. It still throwed the same versioning error.

  • Friday, March 30, 2012 2:51 PM
     
     
    Is there some particular reason that you want to target FxCop 1.36 instead of FxCop 10.0?