Mark assemblies with assembly version

Rule ND2800 .NET Framework Usage / System.Reflection

An assembly identity is: name, version number, culture, public key (if strong-named). .NET uses the version to uniquely identify an assembly and bind to types in strong-named assemblies; by default applications only run with the version they were built with. Matches assemblies not tagged with System.Reflection.AssemblyVersionAttribute.

How to fix

Add a version via System.Reflection.AssemblyVersionAttribute.

CQLinq source

This rule is written in CQLinq, C# LINQ over the NDepend code model. It ships with every new NDepend project: you can read it, adapt it, or use it as a starting point for your own custom rules.

// <Name>Mark assemblies with assembly version</Name>
// <Id>ND2800:MarkAssembliesWithAssemblyVersion</Id>

warnif count > 0 
let isUnityProject = ThirdParty.Assemblies.Any(a => a.Name.StartsWith("UnityEngine"))
from a in Application.Assemblies where 
  !isUnityProject && // Version is not required on Unity assemblies.
                     // You can still use the AssemblyVersionAttribute in Unity context 
                     // as explained here https://forum.unity.com/threads/assemblyinfo-cs-solutions.529418/
  !a.HasAttribute ("System.Reflection.AssemblyVersionAttribute".AllowNoMatch()) &&
  // Make sure the assembly version is not defined through a way different than AssemblyVersionAttribute
  (a.Version == null || a.Version.ToString() == "0.0.0.0")
select new {
   a,
   Debt = 10.ToMinutes().ToDebt(),
   Severity = Severity.High
}

//<Expl>
// The *{0}* should declare a version through the *System.Reflection.AssemblyVersionAttribute*.
//</Expl>

//<Desc>
// An assembly identity is: name, version number, culture, public key (if
// strong-named). .NET uses the version to uniquely identify an assembly
// and bind to types in strong-named assemblies; by default applications
// only run with the version they were built with. Matches assemblies not
// tagged with **System.Reflection.AssemblyVersionAttribute**.
//</Desc>

//<HowToFix>
// Add a version via *System.Reflection.AssemblyVersionAttribute*.
//</HowToFix>

.NET Framework Usage / System.Reflection: all 3 items