Search Amazon:

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 >>

Sign In
  User Id 
  Password 


Submit Your Own Code and Articles




About TheScarms
About TheScarms

Ask me your programming questions

I read every email and answer all I can.

User Feedback: Be the first to add a comment! Items to Show:     

     
You must log in to post feedback.
Comment:    
 

If you use this code, please mention "www.TheScarms.com"

Email this page


TheScarms AppSentinel lets you securely copy protect and create evaluation versions of your software

TheScarms(tm) AppSentinel lets you quickly and easily create evaluation versions of your software and stop unauthorized copying and unregistered use of your programs!

Get your free
trial copy today!


      The World's Number 1 Web Host

© Copyright 2008 TheScarms