Page 9 of
10
<< Previous
1 2
3 4
5 6
7 8
9 10
Next >>
|
Custom FxCop Rule - Do not use Wildcards in Assembly Version Number
Here is an FxCop rule which prevents you from using wildcards in an assembly's
version number. A better programming practice it to explicitly set the version
number in the assemblyinfo file.
While there is no certain way to know that a wildcard was used, we can infer it
by looking at the length of the individual components of the version number. If
any of them are five characters longer, it is a safe bet that they were set by
.NET since most programmers would typically use a shorter number.
C# code for custom FxCop rule:
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Cci;
using Microsoft.FxCop.Sdk;
using Microsoft.FxCop.Sdk.Introspection;
public class DoNotUseWildcardsInVersion : BaseMigrationIntrospectionRule
{
public DoNotUseWildcardsInVersion() : base("DoNotUseWildcardsInVersion")
{
}
public override ProblemCollection Check(Module module)
{
AssemblyNode a = module.ContainingAssembly;
if ((a == null) || (a.Version == null))
return base.Check(module);
string major = a.Version.Major.ToString();
string minor = a.Version.Minor.ToString();
string build = a.Version.Build.ToString();
string revision = a.Version.Revision.ToString();
if (major.Trim().Length.Equals(5))
{
base.Problems.Add(new Problem(GetResolution(module.Name), module));
}
if (minor.Trim().Length.Equals(5))
{
base.Problems.Add(new Problem(GetResolution(module.Name), module));
}
if (build.Trim().Length.Equals(5))
{
base.Problems.Add(new Problem(GetResolution(module.Name), module));
}
if (revision.Trim().Length.Equals(5))
{
base.Problems.Add(new Problem(GetResolution(module.Name), module));
}
return base.Problems;
}
}
Rule definition in the XML rules file:
<Rule TypeName="DoNotUseWildcardsInVersion"
Category="VBMigration" CheckId="AA1001">
<Name>
Do not use wildcards in an assembly's version number
</Name>
<Description>
Wildcards have been used in an assembly's version number..
</Description>
<Url>
http://www.thescarms.com/
</Url>
<Resolution>
Do not use wildcards in an assembly's version number. You should
explicitly set all components of an assembly's version number.
</Resolution>
<MessageLevel Certainty="80">
Warning
</MessageLevel>
<FixCategories>
NonBreaking
</FixCategories>
<Owner />
<Rule>
|
Page 9 of
10
<< Previous
1 2
3 4
5 6
7 8
9 10
Next >>
|
|
About TheScarms
Sample code version info
|