Ola Pessoal,
Estou tentando customizar algumas regras para analise de codigo no visual studio 2008, verificando na internet encontrei algums exemplos para tentar entender o processo, porem o exemplo que eu estou testando esta exibindo um erro.
segui os passo descritos no exemplo, compilei o projeto e copie a dll para a pasta:
C:\Program Files (x86)\Microsoft Visual Studio 9.0\Team Tools\Static Analysis Tools\FxCop\Rules.
A regra aparece na janela do code Analysis. Porém ao compilar um outro projeto usando estas regras o erro é exibido
CA0054 : Error loading rule 'ClassFieldNamePrefixes': The following stream was not found in the assembly manifest: Rules.xml SitCodigoAnalisys
Veja o bloco de codigo:
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.FxCop.Sdk;
namespace TutorialRules
{
class ClassFieldNamePrefixes : BaseIntrospectionRule
{
public ClassFieldNamePrefixes() :
base("ClassFieldNamePrefixes", "TutorialRules.Rules",
typeof(ClassFieldNamePrefixes).Assembly)
{
}
public override ProblemCollection Check(Member member)
{
if (!(member.DeclaringType is ClassNode))
return this.Problems;
Field fld = member as Field;
if (fld == null)
return this.Problems;
if (fld.IsStatic && !fld.Name.Name.StartsWith("g_", StringComparison.Ordinal) &&
fld.Name.Name != "__ENCList")
{
this.Problems.Add(new Problem(this.GetNamedResolution("Static", fld.Name.Name)));
}
else if (!fld.Name.Name.StartsWith("m_", StringComparison.Ordinal) &&
fld.Name.Name != "__ENCList" && fld.Name.Name != "components")
{
this.Problems.Add(new Problem(this.GetNamedResolution("Instance", fld.Name.Name)));
}
return this.Problems;
}
}
}
aqui o xml Rules.xml para exibir as regras ao usuario do visual studio.
<Rules FriendlyName="Tutorial Rules">
<Rule TypeName="ClassFieldNamePrefixes" Category="Rules" CheckId="TT1010">
<Name>Class field names should use the 'm_' and 'g_' suffixes.</Name>
<Description>
Instance fields in classes should begin with the 'm_' prefix.
Static fields in classes should begin with the 'g_' prefix.
</Description>
<Url></Url>
<Resolution Name="Static">Prefix the static field '{0}' with 'm_'.</Resolution>
<Resolution Name="Instance">Prefix the instance field '{0}' with 'g_'.</Resolution>
<MessageLevel Certainty="95">Warning</MessageLevel>
<Email></Email>
<FixCategories>Breaking</FixCategories>
<Owner></Owner>
</Rule>
</Rules>
desde ja agradeço.
Davila