"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.
-
9 марта 2012 г. 10:19
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.
Все ответы
-
9 марта 2012 г. 13:19
-
9 марта 2012 г. 13:29
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.
-
9 марта 2012 г. 14:22
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
-
12 марта 2012 г. 3:05I did that also...You can have a look at the code to verify once.
-
12 марта 2012 г. 13:13
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>- Предложено в качестве ответа Jack Zhai - MSFTMicrosoft Contingent Staff, Moderator 16 марта 2012 г. 1:42
- Помечено в качестве ответа Jack Zhai - MSFTMicrosoft Contingent Staff, Moderator 19 марта 2012 г. 2:13
-
18 марта 2012 г. 5:53
Hi Nicol,
Will definitly try your XML and thanks for your post.
- Помечено в качестве ответа Shiva Reddy.HCL 19 марта 2012 г. 7:04
-
19 марта 2012 г. 2:13Модератор
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
- Помечено в качестве ответа Shiva Reddy.HCL 19 марта 2012 г. 7:04
-
19 марта 2012 г. 7:05
Hi Jack and Nicol,
I thank you both, now I am able to execute my own custom rule. Thanks for your help
Regards,
Siva
-
30 марта 2012 г. 1:20
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.
-
30 марта 2012 г. 14:51Is there some particular reason that you want to target FxCop 1.36 instead of FxCop 10.0?

