Challenge
Create a .NET assembly and manage its version numbering. An assembly is a "logical DLL." It can comprise one or more physical files (which typically use the DLL suffix). An assembly contains Microsoft Intermediate Language (MSIL) code, emitted by compilers supplied with the .NET Framework, and executed using the CLR. An assembly also contains a manifest, which holds version information about the assembly (among other items).
Solution
Create the assembly in C# and version it using the AssemblyVersion attribute. The AssemblyVersion attribute specifies the version number of the assembly, and this is embedded in the manifest. Versions under .NET comprise a major and minor version number, and two further optional build and revision numbers.
The FeedsHowMany method in the CakeInfo class, shown below, is the C# equivalent of the feeds_how_many method implemented as a shared library under Linux in the separate item, "How to Create a UNIX (including Linux) Shared Library." This class is intended to be executed on Windows using the CLR. It is located in the file CakeInfo.cs:
using System.Reflection;<
[assembly: AssemblyVersion("1.0.*")]
namespace CakeUtils<
{
public enum CakeFilling{Sponge, Fruit}
public enum CakeShape{Square, Round, Hexagonal, Other}
public class CakeInfo
public static short FeedsHowMany(short diameter, CakeShape shape,
CakeFilling filling)
{<br />
double munchSizeFactor =
(filling == CakeFilling.Fruit ? 2.5 : 1);
double deadSpaceFactor
switch (shape)
case CakeShape.Square: deadSpaceFactor = 0
break
case CakeShape.Round: deadSpaceFactor = 0.1
break
case CakeShape.Hexagonal: deadSpaceFactor = 0.15
break
default: deadSpaceFactor = 0.2
break
}
short numConsumers = (short)(diameter * munchSizeFactor
(1 - deadSpaceFactor))
return numConsumers
}
}
}
In this example (which uses "1.0.*"), the major version number is 1, the minor version number is 0, and the build and revision numbers are generated automatically when the assembly is built. (When specifying a "*", the build number is set to the number of days since January 1, 2002, and the revision number is set to the number of seconds since midnight, so the values generated are not necessarily sequential. If this is a problem, supply your own values manually).
The assembly can be compiled using the C# compiler, specifying that the result is a library:
csc /t:library CakeInfo.cs
This item is part of a larger body of items that contrast the ways in which versioning and dynamic linking are handled by Windows* and the .NET Common Language Runtime* (CLR), as opposed to by UNIX-based operating systems such as Linux* or Solaris.*
Source
Versioning, Libraries, and Assemblies